stream-lite

所属分类:网络编程
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2018-03-07 20:53:02
上 传 者sh-1993
说明:  具有熟悉的界面和极小的占地面积的简约和模块化函数式 React编程库。,
(A minimalistic and modular functional reactive programming library with familiar interface and tiny footprint.,)

文件列表:
.babelrc.js (482, 2018-03-07)
.npmignore (133, 2018-03-07)
.travis.yml (311, 2018-03-07)
package-lock.json (496407, 2018-03-07)
package.json (2854, 2018-03-07)
src/ (0, 2018-03-07)
src/add/ (0, 2018-03-07)
src/add/all.js (1648, 2018-03-07)
src/add/common.js (440, 2018-03-07)
src/add/operators/ (0, 2018-03-07)
src/add/operators/buffer.js (158, 2018-03-07)
src/add/operators/bufferCount.js (178, 2018-03-07)
src/add/operators/bufferWhen.js (174, 2018-03-07)
src/add/operators/catchError.js (174, 2018-03-07)
src/add/operators/combine.js (162, 2018-03-07)
src/add/operators/combineLatest.js (186, 2018-03-07)
src/add/operators/concat.js (158, 2018-03-07)
src/add/operators/concatMap.js (170, 2018-03-07)
src/add/operators/concatMapTo.js (178, 2018-03-07)
src/add/operators/debounce.js (166, 2018-03-07)
src/add/operators/debounceTime.js (182, 2018-03-07)
src/add/operators/defaultIfEmpty.js (190, 2018-03-07)
src/add/operators/delay.js (154, 2018-03-07)
src/add/operators/distinctUntilChanged.js (214, 2018-03-07)
src/add/operators/every.js (154, 2018-03-07)
src/add/operators/filter.js (158, 2018-03-07)
src/add/operators/first.js (154, 2018-03-07)
src/add/operators/flatMap.js (162, 2018-03-07)
src/add/operators/ignoreElements.js (190, 2018-03-07)
src/add/operators/last.js (150, 2018-03-07)
src/add/operators/map.js (146, 2018-03-07)
src/add/operators/mapTo.js (154, 2018-03-07)
src/add/operators/merge.js (154, 2018-03-07)
src/add/operators/pairwise.js (166, 2018-03-07)
src/add/operators/partition.js (170, 2018-03-07)
src/add/operators/pluck.js (154, 2018-03-07)
src/add/operators/scan.js (150, 2018-03-07)
src/add/operators/single.js (158, 2018-03-07)
... ...

stream-lite

The power of streams, without the overhead.
Extremely small and simple reactive programming library.

npm travis build dependencies codecov coverage semantic-release Commitizen friendly

## Features: - [Extremely small](https://github.com/pshev/stream-lite/blob/master/#size). - Familiar interface (mostly replicating RxJS's API) - Modular. Add as little or as much functionality as you want - Lazy streams (only active once subscribed to) - Only ["hot"](https://github.com/pshev/stream-lite/blob/master/https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339) streams - [Pipeable operators](https://github.com/pshev/stream-lite/blob/master/https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md) support - [Fantasy Observable](https://github.com/pshev/stream-lite/blob/master/https://github.com/staltz/fantasy-observable) compliant - More than 50 operators and factories available ## Installation Assuming you use [npm](https://github.com/pshev/stream-lite/blob/master/https://www.npmjs.com/) as your package manager: ```text npm install --save stream-lite ``` This package includes both a [CommonJS](https://github.com/pshev/stream-lite/blob/master/https://nodejs.org/docs/latest/api/modules.html) and [ES2015](https://github.com/pshev/stream-lite/blob/master/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) based modules.
You can use them from [Node](https://github.com/pshev/stream-lite/blob/master/https://nodejs.org/en/) environment or if you are building for the browser you can use a module bundler like [Webpack](https://github.com/pshev/stream-lite/blob/master/https://webpack.js.org/), [Browserify](https://github.com/pshev/stream-lite/blob/master/http://browserify.org/), or [Rollup](https://github.com/pshev/stream-lite/blob/master/http://rollupjs.org).
If you want to experiment and play around with Amnis without a module bundler or you don't use one - that's OK. The `stream-lite` npm package includes precompiled production and development UMD builds in the `umd` folder. You can just drop a UMD build as a ` ``` ## Import and Usage The following guide assumes you use ES2015+ but you don't have to.
There are a few different ways of importing the functionality that you need. To import the entire set of functionality: ```js import Stream from 'stream-lite' import 'stream/add/all' Stream .of(1,2,3) .map(x => x * 2) .subscribe(x => console.log(x)) ``` However the `stream-lite` module encourages shipping only the scripts that you will actually use.
One way of doing that is to add to Stream's prototype only the methods you actually need: ```js import Stream from 'stream-lite' import 'stream-lite/add/statics/of' import 'stream-lite/add/operators/map' Stream .of(1,2,3) .map(x => x * 2) .subscribe(x => console.log(x)) ``` To not add static methods to Stream, you can import them as pure functions: ```js import {of} from 'stream-lite/statics' import 'stream-lite/add/operators/map' of(1,2,3) .map(x => x * 2) .subscribe(x => console.log(x)) ``` To take this one step further and avoid patching the Stream's prototype altogether, you can use `pipeable operators`.
If you are not familiar with pipeable operators you can learn about them [here](https://github.com/pshev/stream-lite/blob/master/https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md).
```js import {of} from 'stream-lite/statics' import {map, filter} from 'stream-lite/operators' of(1,2,3).pipe( filter(x => x % 2 === 0), map(x => x * 2) ) .subscribe(x => console.log(x)) ``` The `stream-lite` core also provides a pipeable `subscribe` for your convenience.
So you can bring the subscribe method inside your pipe and write the code above like so: ```js import {subscribe} from 'stream-lite' import {of} from 'stream-lite/statics' import {map, filter} from 'stream-lite/operators' of(1,2,3).pipe( filter(x => x % 2 === 0), map(x => x * 2), subscribe(x => console.log(x)) ) ``` Or if you use the proposed JavaScript [`pipe operator`](https://github.com/pshev/stream-lite/blob/master/https://github.com/tc39/proposal-pipeline-operator): ```js import {subscribe} from 'stream-lite' import {of} from 'stream-lite/statics' import {map, filter} from 'stream-lite/operators' of(1,2,3) |> filter(x => x % 2 === 0) |> map(x => x * 2) |> subscribe(x => console.log(x)) ``` > Please note: This additional syntax requires [transpiler support](https://github.com/pshev/stream-lite/blob/master/https://www.npmjs.com/package/babel-plugin-transform-pipeline-operator). ## Size The `stream-lite` package is built to bring as little overhead to your project as possible.
##### core The core of the library includes the `create` function and a few prototype methods, like `subscribe` and `pipe`.
This core is **~1KB** gzipped.
##### common A common usage will probably include around 15 most common methods and operators, which should bring about **1.8KB** to your app if you use tree-shaking.
##### everything If for some reason you feel the need to import all available operators and factories, that option is also available.
That includes more than 50 operators and factories, and will make your app heavier by about **3.5KB** gzipped. ## API The vast majority of factories and operators are too similar to the API of RxJS, so most links will point you to RxJS documentation.
However there are some that don't exist in RxJS or ones with a different API. Those are marked with an astrix (*) and their documentation you will find below.
Operators marked with are also available as statics. #### Factories - [`create`](https://github.com/pshev/stream-lite/blob/master/#create)* - [`of`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/of.html) - [`empty`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/empty.html) - [`never`](https://github.com/pshev/stream-lite/blob/master/https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/never.md) - [`error`](https://github.com/pshev/stream-lite/blob/master/#error)* - [`fromArray`](https://github.com/pshev/stream-lite/blob/master/#fromArray)* - [`fromObservable`](https://github.com/pshev/stream-lite/blob/master/#fromObservable)* - [`fromEvent`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/fromevent.html) - [`fromPromise`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/frompromise.html) - [`interval`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/interval.html) - [`range`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/range.html) #### Methods and Operators - [`subscribe`](https://github.com/pshev/stream-lite/blob/master/#subscribe)* - [`map`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/map.html) - [`mapTo`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/mapto.html) - [`filter`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/filter.html) - [`scan`](https://github.com/pshev/stream-lite/blob/master/#scan)* - [`pluck`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/pluck.html) - [`single`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/single.html) - [`first`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/first.html) - [`last`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/last.html) - [`every`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/conditional/every.html) - [`defaultIfEmpty`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/conditional/defaultifempty.html) - [`tap`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/utility/do.html) - [`pairwise`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/pairwise.html) - [`delay`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/utility/delay.html) - [`buffer`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/buffer.html) - [`bufferWhen`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/bufferwhen.html) - [`bufferCount`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/buffercount.html) - [`debounce`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/debounce.html) - [`debounceTime`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/debouncetime.html) - [`throttle`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/throttle.html) - [`throttleTime`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/throttletime.html) - [`distinctUntilChanged`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/distinctuntilchanged.html) - [`mergeMap`](https://github.com/pshev/stream-lite/blob/master/#flatMap)* - [`flatMap`](https://github.com/pshev/stream-lite/blob/master/#flatMap)* - [`switchMap`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/switchmap.html) - [`concatMap`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/concatmap.html) - [`concatMapTo`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/concatmapto.html) - [`catchError`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/error_handling/catch.html) - [`partition`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/partition.html) - [`concat`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/concat.html) - [`merge`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/merge.html) - [`combine`](https://github.com/pshev/stream-lite/blob/master/#combine)* - [`combineLatest`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/combinelatest.html) - [`startWith`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/startwith.html) - [`skip`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/skip.html) - [`skipUntil`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/skipuntil.html) - [`skipWhile`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/skipwhile.html) - [`ignoreElements`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/ignoreelements.html) - [`take`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/take.html) - [`takeUntil`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/takeuntil.html) - [`takeWhile`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/filtering/takewhile.html) - [`withLatestFrom`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/withlatestfrom.html) - [`withValue`](https://github.com/pshev/stream-lite/blob/master/#withValue)* ## ### subscribe You can call it in two different ways:
Either passing three callbacks in this following order: `next`, `error`, `complete`. ```js import {of} from 'stream-lite/statics' of(1, 2, 3).subscribe( x => console.log(x), err => console.error("There's an error!", err), () => console.log("We're done") ) ``` Or passing a subscription object with the `next`, `error`, `complete` functions as keys. ```js import {of} from 'stream-lite/statics' of(1, 2, 3).subscribe({ next: x => console.log(x), error: err => console.error("There's an error!", err), complete: () => console.log("We're done") }) ``` You can also use a pipeable version of `subscribe`: ```js import {subscribe} from 'stream-lite' import {of} from 'stream-lite/statics' import {map} from 'stream-lite/operators' of(1,2,3).pipe( map(x => x * 2), subscribe(x => console.log(x)) ) ``` ### create This is the only thing that is included in the core object exported from `stream-lite`. Most use-cases for creating a stream involve calling other factory functions, like `fromEvent` or `fromPromise`, etc.
Those are all abstractions on top of the `create` factory. Usually you want to use those. However, sometimes you may need more control and the way you achieve that in `stream-lite` is different from `RxJS`. #### Creating a stream with a producer A Producer is a simple JavaScript object with `start` and `stop` functions. `start` function will be called when the first subscriber subscribes to it. `stop` function will be called when the last subscriber unsubscribes or the stream completes or it errors. Here is an example of a producer that is used inside the `interval` factory (except with `step` parameter hard-coded): ```js const producer = { counter: 0, id: 0, start: function(consumer) { this.id = setInterval(() => consumer.next(this.counter++), 1000) }, stop: function() { clearInterval(this.id) } } ``` Armed with that producer we can now easily create a new stream:
```js import {create} from 'stream-lite' const myIntervalStream = create(producer) ``` When subscribed to it will start emitting values every second. #### Creating a stream without a producer Sometimes you just want to create an empty stream and manually push values into it. You can achieve this functionality by calling `create` with no parameters:
```js import {create} from 'stream-lite' const manuallyControlledStream = create() manuallyControlledStream.subscribe(x => console.log(x)) manuallyControlledStream.next(1) manuallyControlledStream.next(2) // logs 1, 2 ``` This is sort of similar to how you would use RxJs's Subject. ### fromArray Equivalent to calling RxJS's [`from`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/from.html) with an array. ### fromObservable Equivalent to calling RxJS's [`from`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/from.html) with an observable. ### error Same as RxJS's [`_throw`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/creation/throw.html) but with a friendlier name. ### scan Mostly equivalent to calling RxJS's [`scan`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/scan.html) except currently it requires an initial value parameter. ### flatMap Alias: `mergeMap`. Equivalent to RxJS's [`flatMap`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/transformation/mergemap.html) without the support for an optional 3rd parameter `concurrent`. ### combine Simply an alias for [`combineLatest`](https://github.com/pshev/stream-lite/blob/master/https://www.learnrxjs.io/operators/combination/combinelatest.html). ### withValue Allows to emit an extra parameter in addition to one emitted from source stream.
```js import {subscribe} from 'stream-lite' import {of} from 'stream-lite/statics' import {withValue} from 'stream-lite/operators' of(4) |> withValue(x => x / 2) |> subscribe(x => console.log(x)) // logs [4, 2] ``` ## License MIT

近期下载者

相关文件


收藏者