Introduction
Basic
fluth
is a Promise-like streaming programming library that excels at reactive programming.
If we consider promise
as a publisher and the then
method as a subscriber, a promise
can only publish once.
fluth
enhances promise
by allowing it to publish continuously!
javascript
import { $ } from "fluth";
const promise$ = $();
promise$.then(
(r) => console.log("resolve", r),
(e) => console.log("reject", e)
);
promise$.next(1);
promise$.next(Promise.reject(2));
promise$.next(3);
// Logs:
// resolve 1
// reject 2
// resolve 3
- Compared to other streaming programming libraries,
fluth
is simpler and easier to use, with low learning costs. - Compared to
promise
,fluth
can publish continuously and supports subscription cancellation.
Comparison with rxjs
rxjs
is the current mainstream streaming programming library. Compared with fluth
, there are several differences:
fluth
is very easy to get started with - if you know how to usepromise
, you can use itfluth
can chain observers, whilerxjs
observers are concurrentfluth
divides stream operations intooperator
andchainPlugin
.chainPlugin
only handles stream composition and can be called in a chain between observers
javascript
// rxjs:
stream$.pipe(operator1, operator2, operator3);
stream$.subscribe(observer1);
stream$.subscribe(observer2);
stream$.subscribe(observer3);
javascript
//fluth:
stream$.use(chainPlugin1, chainPlugin2, chainPlugin3)
stream$
.then(observer1)
.chainPlugin1()
.then(observer2)
.chainPlugin2()
.then(observer3)
.chainPlugin3();
stream$.next(1);
operator1(stream$1, stream$2);
operator2(stream$2, stream$3);