Skip to content

Commit

Permalink
feat(normalizr): first normalized data
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Jul 9, 2016
1 parent 44115bf commit 5893e58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions extension-normalizr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"dependencies": {
"lodash": "^4.13.1",
"normalizr": "^2.1.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"react-redux": "^4.4.5",
Expand Down
5 changes: 5 additions & 0 deletions extension-normalizr/src/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { map } from 'lodash';
import { arrayOf, normalize } from 'normalizr';
import trackSchema from '../schemas/track';
import { CLIENT_ID, REDIRECT_URI } from '../constants/auth';
import * as actionTypes from '../constants/actionTypes';
import { setTracks } from '../actions/track';
Expand Down Expand Up @@ -29,6 +32,8 @@ function fetchStream(me, session) {
fetch(`//api.soundcloud.com/me/activities?limit=20&offset=0&oauth_token=${session.oauth_token}`)
.then((response) => response.json())
.then((data) => {
const normalized = normalize(map(data.collection, 'origin'), arrayOf(trackSchema));
console.log(normalized);
dispatch(setTracks(data.collection));
});
};
Expand Down
5 changes: 5 additions & 0 deletions extension-normalizr/src/schemas/track.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Schema } from 'normalizr';

const trackSchema = new Schema('tracks');

export default trackSchema;

0 comments on commit 5893e58

Please sign in to comment.