Skip to content

Instantly share code, notes, and snippets.

@staydecent
Created May 27, 2017 05:02
Show Gist options
  • Select an option

  • Save staydecent/928253b0824f42e6343ea70c250f4438 to your computer and use it in GitHub Desktop.

Select an option

Save staydecent/928253b0824f42e6343ea70c250f4438 to your computer and use it in GitHub Desktop.
Ramda over Recompose and Reselect (WIP)
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