Created
August 31, 2018 08:22
-
-
Save raine/c0670e3e3be2927d0181df0d90081efe to your computer and use it in GitHub Desktop.
This file contains 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 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