JSPM

  • Created
  • Published
  • Downloads 227
  • Score
    100M100P100Q82469F
  • License Apache-2.0

To be Willin is to be willing.

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.

github npm npm npm Maintainability Test Coverage

你的关注是我最大的动力。 Your Star 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

  1. Add your own operator
  2. Update Readme Doc (List / Usage)
  3. Make a PR

License

Apache 2.0

通过支付宝捐赠:

qr