Example code for creating a store with status and typeahead fetching action is shown below:
import fetchival from 'fetchival';
import {from} from 'rxjs';
import {map, filter, debounceTime, distinctUntilChanged, tap, flatMap} from 'rxjs/operators';
import {createStore, createAction, createStatus} from 'rxstate';
Â
const status = createStatus();
Â
const getTypeahead = createAction();
const typeahead$ = getTypeahead.$.pipe(
  map(e => e.target.value),
  filter(q => q.length > 3),
  debounceTime(300),
  distinctUntilChanged(),
  tap(() => status('loading')),
  flatMap(q => from(fetchival(typeaheadAPI).post({q}))),
  tap(() => status('done'))
);
Â
const streams = [status.$, typeahead$];
const store = createStore({streams, defaultState: {init: true}});
Â
store.subscribe(state => {
  console.log(state);
 Â
});
Â
getTypeahead('keyword');
const combinator = (_, data) => data;
const store = createStore({streams, defaultState, combinator});
const status = createStatus('customStatus');
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4