Skip to content

Commit

Permalink
fix readme type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo-Marques committed Apr 30, 2018
1 parent 7e7cfd3 commit 36733c7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const fetchUser = id => fetch(`/users/${id}`).then(res => res.json())
const UserFetcher = new PromiseMiddleware(fetchUser)

// tell the cache how to get the entity's id based on the arguments the fetch request is given
const idGetter = (...args) => args[0]
const idGetter = id => id

// cache requests using a normalized state tree
cache(idGetter)(UserFetcher)
Expand All @@ -50,10 +50,10 @@ import UserFetcher from 'fetchers/User'
// args will be an array of the arguments provided when we call "request" and res will be whatever the promise
// originally given to the PromiseMiddleware resolved with
// returns a callback to unsubscribe the middleware
const unsubscribe = UserFetcher.onSuccess(({ res, args }) => onUserFetchSuccess(res, idGetter(...args)))
const unsubscribe = UserFetcher.onSuccess(onUserFetchSuccess)

function onUserFetchSuccess({ res }) {
console.log(`Got the user with the id ${id}!`, res)
function onUserFetchSuccess({ res, args }) {
console.log(`Got the user with the id ${idGetter(...args)}!`, res)
}

UserFetcher.request(1)
Expand Down

0 comments on commit 36733c7

Please sign in to comment.