3.2.6 • Published 10 months ago

fastrx v3.2.6

Weekly downloads
31
License
MIT
Repository
github
Last release
10 months ago

#rx4rx-fast the fast rxjs implemention

#install

npm i fastrx

#usage

import rx from 'fastrx';

rx.of(1,2,3).filter(x=>x<2).subscribe(console.log)

or

with tree-shaking

import {pipe,fromArray,filter,subscribe} from 'fastrx/pipe';
pipe(fromArray([1,2,3]), filter(x=>x<2), subscribe(console.log))

with "@babel/plugin-proposal-pipeline-operator"

import {fromArray,filter,subscribe} from 'fastrx/pipe';
fromArray([1,2,3]) |> filter(x=>x<2) |> subscribe(console.log)

dataflow for 1000000 source events

libop/ssamples
rx4rx-lite11.29 op/s ± 1.47%(56 samples)
rx4rx-fast22.56 op/s ± 1.77%(57 samples)
cb-basics9.56 op/s ± 1.73%(49 samples)
xstream5.37 op/s ± 0.68%(30 samples)
most17.32 op/s ± 1.93%(82 samples)
rx 66.28 op/s ± 3.10%(35 samples)

#extensible

Observable.create way

import rx from 'fastrx';
const myObservable = rx(sink=>{
    sink.next('data')
    sink.complete()
})
myObservable.subscribe(console.log)

or

import {pipe,subscribe} from 'fastrx/pipe';
const myObservable = ()=>sink=>{
    sink.next('data')
    sink.complete()
}
pipe(myObservable(), subscribe(console.log))

add to library

import rx from 'fastrx';
rx.myObservable = (args) => sink => {
    const id = setTimeout(()=>{
        sink.next(args)
        sink.complete()
    })
    sink.defer([clearTimeout,null,id])
    //or sink.defer(()=>clearTimeout(id))
}

then you can use your observable anywhere

import rx from 'fastrx';
rx.myObservable('something').subscribe(console.log)

vue2.0 usage

import rx from "fastrx";
import RxComputed from "fastrx/vue";
Vue.use(RxComputed);
<template>
    <div @click="onClick1" :style="{top:y+'px',left:x+'px'}">
        <span>{{test1}}</span>
        <span>{{test0}}</span>
    </div>
</template>
<script>
import rx from 'fastrx'
export default {
   rxComputed:{
       test0:()=>rx.interval(1000).take(10),//简单的订阅
       test_watch:{//使用watch触发Observable发射数据
           get:ob=>ob.switchMapTo(rx.interval(1000)).map(x=>10-x)
           watch:"test1"
       },
       test1:{//使用设置方法的方式触发,可以提供给事件回调
           get:ob=>ob.switchMap(rx.timer(1000)),
           handler:"onClick1"
       },
       test2:{
           call:true,//调用test2方法而不是设置属性
           get:ob=>ob.switchMap(e=>rx.timer(1000).map(()=>e)),
           handler:"onClick1"
       },
       "x,y":{//采用解构,将结果对象中的x,y属性分别写入vue实例中的x和y属性
            get:ob=>ob.switchMap(e=>rx.timer(1000).map(()=>({x:e.screenX,y:e.screenY}))),
           handler:"onClick1",
           default:{x:0,y:0}//设置默认值
        }
   },
   methods:{
       test2(e){
           console.log(e)
       }
   }
}
</script>

vue3.0 usage

<template>
    <div @click="handler"></div>
    <div>{{count}}</div>
    <div>{{count2}}</div>
</template>
<script>
import rx from 'fastrx'
export default {
    setup(){
        const ob = rx.eventHandler()
        const count =  ob.switchMapTo(rx.interval(1000)).toRef()
        const count2 = rx.watch(count).map(x=>x*2).toRef()
        return {handler:ob.handler,count,count2}
    }
}
</script>
3.2.6

10 months ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.2.5

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.1.4

3 years ago

3.0.12

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.10

4 years ago

3.0.11

4 years ago

3.0.9

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.6

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.5

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago