Skip to content

Instantly share code, notes, and snippets.

@raine
Created August 31, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raine/c0670e3e3be2927d0181df0d90081efe to your computer and use it in GitHub Desktop.
Save raine/c0670e3e3be2927d0181df0d90081efe to your computer and use it in GitHub Desktop.
const params = U.view(['search', searchParamsL], location)
const search = U.atom(params.get().search || '')
const debouncedSearch = U.debounce(300, search)
debouncedSearch
.onValue(q => params.modify(
q ? R.assoc('search', q) : R.dissoc('search')
))
const items = U.thru(
debouncedSearch,
U.flatMapLatest(s =>
fetchJSON(`http://localhost:3000/items`)
),
U.startWith([])
)
const state = U.molecule({
search,
items
})
ReactDOM.render(
<App
search={U.view('search', state)}
items={U.view('items', state)}
/>,
document.getElementById('root')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment