Skip to content

Instantly share code, notes, and snippets.

const colors = require('css-color-list')()
// Returns an observable that emits a color every 10ms.
// Stops when we've gone through every color.
const getColorsObservable = () =>
Rx.Observable.interval(10)
.map(i => colors[i])
.takeWhile(color => color != null)
const defaultState = { search: '', results: [] }
const store = createStore((state = defaultState, action) => {
switch (action.type) {
case 'SET_SEARCH':
return { ...state, search: action.search, results: [] }
case 'ADD_RESULTS':
return { ...state, results: state.results.concat(action.results) }
default:
return state
}
const App = connect(state => state, dispatch => ({
setSearch: e => {
dispatch({ type: 'SET_SEARCH', search: e.target.value })
}
}))(({ search, results, setSearch }) => (
<div>
<input value={search} onChange={setSearch} />
{results.map(result => (
<div key={result}>{result}</div>
))}
Rx.Observable.from(store)
.map(state => state.search)
.distinctUntilChanged()
Rx.Observable.from(store)
.map(state => state.search)
.distinctUntilChanged()
.switchMap(search => (
getColorsObservable()
.filter(color => color.includes(search))
))
.subscribe(result => {
store.dispatch({ type: 'ADD_RESULT', result })
})
(function (root, wrapper) {
if (typeof define == "function" && define.amd) define([], function () {
return wrapper;
});else if (typeof module == "object" && module.exports) module.exports = wrapper;else (root.nbind = root.nbind || {}).init = wrapper;
})(this, function (Module, cb) {
if (typeof Module == "function") {
cb = Module;Module = {};
}Module.onRuntimeInitialized = function (init, cb) {
return function () {
if (init) init.apply(this, arguments);try {
<!doctype html>
<title>Dropdown</title>
<style>
input {
box-sizing: border-box;
width: 200px;
}
.options {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
const createDataFetcher = (url) => {
let result = null
let promise = null
return () => {
if (result != null) {
return result;
}
if (promise === null) {