Last active
March 14, 2016 00:05
-
-
Save brigand/16074e8a5cc208c05447 to your computer and use it in GitHub Desktop.
react-obcache - api redesign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ObCache from 'obcache'; | |
var cache = new ObCache(); | |
cache.register('userInfo', ([id]) => functionThatReturnsAPromise(id)); | |
export default cache; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import cache from './cache'; | |
import {providesCacheObserver} from 'react-obcache'; | |
export class UserInfo extends React.Component { | |
renderWithCache = (getFromCache) => { | |
var user = getFromCache('userInfo', this.props.userId); | |
if (user.error) return <div>404</div>; | |
if (!user.data) return <div>Loading</div>; | |
return ( | |
<div> | |
{user.data.firstName} {user.lastName} | |
</div> | |
); | |
} | |
render() { | |
this.props.renderAndTrack(this.renderWithCache); | |
} | |
} | |
export default providesCacheObserver({cache}, UserInfo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment