Skip to content

Repository files navigation

ractor-callbag

Callbag middleware for Ractor

Usage

import{CallbagStore}from"ractor-callbag";import{ChangeTab}from"./ChangeTab";import{map,fromPromise,pipe}from"callbag-basics";importmapPromisefrom"callbag-map-promise";importswitchMapfrom"callbag-flat-map-operator";exportclassTabStoreextendsCallbagStore{state={content: "",actionNames: []};preStart(){this.context.system.eventStream.on("*",obj=>{constactionNames=[...this.state.actionNames];actionNames.push(obj.__proto__.constructor.name);this.setState({ actionNames });});}createReceive(){returnthis.receiveBuilder().match(ChangeTab,changeTab$=>pipe(changeTab$,switchMap(changeTab=>changeTab.tabid===1
? fromPromise(api1000())
: fromPromise(api3000())),map(content=>({ content })))).build();}}functionapi1000(){returnnewPromise((resolve,reject)=>{setTimeout(()=>resolve("first"),1000);});}functionapi3000(){returnnewPromise((resolve,reject)=>{setTimeout(()=>resolve("second"),3000);});}

Demo

About

Callbag middleware for Ractor

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages