A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/rxstate below:

rxstate - npm

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