Created
May 27, 2017 05:02
-
-
Save staydecent/928253b0824f42e6343ea70c250f4438 to your computer and use it in GitHub Desktop.
Ramda over Recompose and Reselect (WIP)
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
| const Preact = require('preact') | |
| const atom = require('atom') | |
| const {reducer, set, update, remove} = require('atom-lens-reducer') | |
| const pipe = require('ramda/src/pipe') | |
| const memoize = require('ramda/src/memoize') | |
| const find = require('ramda/src/find') | |
| const propEq = require('ramda/src/propEq') | |
| const store = atom(reducer, { | |
| // We'll fake the URL, and pretend we are at this path: | |
| url: '/item/2', | |
| items: [ | |
| {id: 2, title: 'cool'}, | |
| {id: 1, title: 'neat'}, | |
| {id: 3, title: 'rad'} | |
| ] | |
| }) | |
| const {render, h, Component} = Preact | |
| const ItemRender = ({item, index}) => | |
| h('li', {onclick: (ev) => remove(['items', index])}, [item.title]) | |
| const Item = pipe( | |
| ) | |
| class Main extends Component { | |
| constructor () { | |
| super() | |
| this.state = store.getState() | |
| } | |
| componentDidMount () { | |
| store.subscribe(() => this.setState(store.getState())) | |
| } | |
| // Pretend we are using Preact-Router or similar: | |
| // <Router> | |
| // <Main path='/item/:itemId' /> | |
| // </Router> | |
| // So we'd get the `itemId` as a prop, and our entire atom state object | |
| render ({itemId}, state) { | |
| return h('ul', null, state.items.map((item) => h(Item, )) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment