Package Exports
- v0
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (v0) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
v0
Useful Rxjs Operators & Utils.
你的
关注
是我最大的动力。 YourStar
is the best gift.
Install
npm i --save rxjs v0
# or
yarn add rxjs v0
Usage
中文文档参考: rx.js.cool 中的【进阶(Advanced)】章节系列文章
Operators:
- delayRetry
- tapAsync
Utils:
- RxPromise
delayRetry
{
maxAttempts?: number;
duration?: number;
}
Defaults:
{
maxAttempts = 3,
duration = 1000
}
Usage:
import { delayRetry } from 'v0';
source$.pipe(
// ...
// Retry all options in current pipe
delayRetry({
maxAttempts: 2,
duration: 200
}),
// catchError is needed
catchError((error) => of(error))
);
tapAsync
Just like tap, support async/await (promise) function.
Usage:
import { tapAsync } from 'v0';
source$.pipe(
tapAsync(async (val) => {
await SomeFn(val);
})
);
RxPromise
// RxPromise<T, R = Error> extends Observable<T>
const mockedPromise = new RxPromise(resolver);
Type of resolver
:
(resolve: (r: T) => void, reject: (r: R) => void) => void
Example,transform mongoose exec
to observable:
import mongoose from 'mongoose';
import { RxPromise } from 'v0';
mongoose.Promise = RxPromise;
mongoose.connect('mongodb://localhost/test', { useNewUrlParser: true, useUnifiedTopology: true });
const kittySchema = new mongoose.Schema({
name: String
});
const Kitten = mongoose.model('Kitten', kittySchema);
const s$ = <Observable<Record<string, unknown>[]>>(<any>Kitten.find().exec());
// or
// const s$ = (Kitten.find().exec()) as any) as Observable<Record<string, unknown>[]>;
s$.subscribe({
next(v) {
console.log(v);
},
complete() {
console.log('ended');
}
});
Contribute
- Add your own operator
- Update Readme Doc (List / Usage)
- Make a PR
License
Apache 2.0
通过支付宝捐赠: