Skip to content

Commit

Permalink
[ci skip] update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Dec 12, 2016
1 parent cdd68db commit 8cb262e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const POSTS = 'POSTS.'
// different collections. Here's one way to do it:

const reducer = combineReducers({
users: prefixReducer(USERS)(keyedCollectionReducer()),
posts: prefixReducer(POSTS)(keyedCollectionReducer()),
users: keyedCollectionReducer({enhance: prefixReducer(USERS)}),
posts: keyedCollectionReducer({enhance: prefixReducer(POSTS)}),
})

const userActions = mapValues(actions, prefixActionCreator(USERS))
Expand All @@ -51,8 +51,8 @@ store.dispatch(userActions.update('28nkdjas9i23kjsdaf', {
console.log(store.getState())
```

After this `state.toJS()` will look like:
```json
The state will look like this:
```
Map {
"users": Map {
"28nkdjas9i23kjsdaf": Map {
Expand Down
35 changes: 35 additions & 0 deletions temp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {reducer as keyedCollectionReducer, actions} from './lib/keyedCollection'
import {createStore} from 'redux'
import {prefixActionCreator, prefixReducer} from 'mindfront-redux-utils'
import {combineReducers} from 'mindfront-redux-utils-immutable'
import mapValues from 'lodash.mapvalues'

const USERS = 'USERS.'
const POSTS = 'POSTS.'

// the keyed collection action types are just INSERT, UPDATE, REMOVE, and BATCH,
// so you have to decorate the action creators and reducer to distinguish between
// different collections. Here's one way to do it:

const reducer = combineReducers({
users: keyedCollectionReducer({enhance: prefixReducer(USERS)}),
posts: keyedCollectionReducer({enhance: prefixReducer(POSTS)}),
})

const userActions = mapValues(actions, prefixActionCreator(USERS))
const postActions = mapValues(actions, prefixActionCreator(POSTS))

const store = createStore(reducer)

store.dispatch(userActions.batch([
userActions.insert('28nkdjas9i23kjsdaf', {
username: 'jimbob',
firstName: 'Jim',
lastName: 'Bob',
}),
// userActions.update('28nkdjas9i23kjsdaf', {
// email: '[email protected]',
// }),
]))

console.log(store.getState().toJS())

0 comments on commit 8cb262e

Please sign in to comment.