Skip to content

Commit 3e62388

Browse files
committed
upgrade rxjs to v5
1 parent c10cf1d commit 3e62388

File tree

7 files changed

+43
-26
lines changed

7 files changed

+43
-26
lines changed

lib/engine/most.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function Engine() {
99
travelStream.send = travelStream.next.bind(travelStream);
1010

1111
function flatObserve(actionsSinks, f){
12-
return mergeArray(actionsSinks)
12+
let subscriptions = mergeArray(actionsSinks)
1313
.recoverWith(e => {
1414
console.error('There is Error in your reducer:',e, e.stack)
1515
return of(x=>x)
@@ -18,6 +18,8 @@ export default function Engine() {
1818
next:f,
1919
error: (e)=>console.error('Something is Wrong:',e, e.stack),
2020
});
21+
subscriptions.isDisposed = subscriptions.disposable.disposed
22+
return subscriptions;
2123
}
2224
historyStream.travel = travelStream;
2325
return {intentStream, flatObserve, historyStream}

lib/engine/rx.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import Rx from 'rx'
1+
import {Subject} from 'rxjs/Subject'
2+
import {Observable} from 'rxjs/Observable'
3+
import {from} from 'most'
4+
import 'rxjs/add/operator/map'
5+
import 'rxjs/add/operator/take'
6+
import 'rxjs/add/observable/from'
7+
import 'rxjs/add/operator/mergeAll'
28
export default function rxEngine() {
3-
Rx.Subject.prototype.send = Rx.Subject.prototype.onNext
4-
let historyStream = new Rx.Subject();
5-
historyStream.travel = new Rx.Subject();
6-
let intentStream = new Rx.Subject();
9+
Subject.prototype.send = Subject.prototype.next
10+
let historyStream = new Subject();
11+
historyStream.travel = new Subject();
12+
let intentStream = new Subject();
713
function flatObserve(actionsSinks, f){
8-
return Rx.Observable.from(actionsSinks).mergeAll().subscribe(f);
14+
let subscriptions = Observable.from(actionsSinks).mergeAll().subscribe(
15+
f,
16+
(e)=>console.error('Something is Wrong:',e, e.stack)
17+
)
18+
subscriptions.unsubscribe = subscriptions.dispose
19+
return subscriptions
920
}
1021
return {intentStream,flatObserve,historyStream}
1122
}

lib/history.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import {from} from 'most'
12
export default function initHistory(contextHistory){
2-
let history = contextHistory
3+
let history =from(contextHistory)
34
.timestamp()
45
.scan((acc,state)=>{
56
acc.push(state)
67
return acc;
78
}, [])
89
.multicast()
9-
let travel = contextHistory.travel
10+
let travel = from(contextHistory.travel)
1011
history.cursor = -1
1112
history.travel = travel
1213
.sample((offset,states)=>{

lib/react-most.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react'
22
import initHistory from './history'
3+
import {from} from 'most'
34
import mostEngine from './engine/most'
45
import mergeAll from 'ramda/src/mergeAll'
56
import pick from 'ramda/src/pick'
67
import keys from 'ramda/src/keys'
78
// unfortunately React doesn't support symbol as context key yet, so let me just preteding using Symbol until react implement the Symbol version of Object.assign
8-
const INTENT_STREAM = "__reactive.react.intentStream__";
9-
const HISTORY_STREAM = "__reactive.react.historyStream__";
9+
export const INTENT_STREAM = "__reactive.react.intentStream__";
10+
export const HISTORY_STREAM = "__reactive.react.historyStream__";
1011
const EACH_FLATMAP = "__reactive.react.flatObserve__";
1112

1213
const CONTEXT_TYPE = {
@@ -39,7 +40,7 @@ export function connect(main, initprops={}) {
3940
super(props, context);
4041
if(initprops.history || props.history){
4142
initprops.history = initHistory(context[HISTORY_STREAM])
42-
initprops.history.travel.observe(state=>{
43+
initprops.history.travel.forEach(state=>{
4344
return this.setState(state)
4445
})
4546
}
@@ -55,7 +56,7 @@ export function connect(main, initprops={}) {
5556
}
5657
componentDidMount(){
5758
this.subscriptions = this.context[EACH_FLATMAP](this.sink$, (action)=>{
58-
if(this.subscriptions && this.subscriptions.disposable.disposed)
59+
if(this.subscriptions && this.subscriptions.isDisposed)
5960
return
6061
else if(action instanceof Function) {
6162
this.setState((prevState, props)=>{
@@ -95,9 +96,9 @@ let Most = React.createClass({
9596
/* istanbul ignore next */
9697
if(process.env.NODE_ENV==='debug') {
9798
if(engineClass == mostEngine) {
98-
engine.intentStream.timestamp()
99+
from(engine.intentStream).timestamp()
99100
.observe(stamp=>console.log(`[${new Date(stamp.time).toJSON()}][INTENT]:}`, stamp.value));
100-
engine.historyStream.timestamp()
101+
from(engine.historyStream).timestamp()
101102
.observe(stamp=>console.log(`[${new Date(stamp.time).toJSON()}][STATE]:}`, stamp.value));
102103
}
103104
}
@@ -126,7 +127,7 @@ function actionsAndSinks(sinks, self){
126127
self.context[INTENT_STREAM].send(f(e));
127128
},
128129
fromPromise(p){
129-
p.then(self.context[INTENT_STREAM].send);
130+
p.then(x=>self.context[INTENT_STREAM].send(x));
130131
}
131132
};
132133
for(let name in sinks){

lib/test-utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import {from } from 'most'
2-
2+
import {INTENT_STREAM, HISTORY_STREAM} from './react-most'
33
function getStreamOf(component, name) {
4-
let s = component.context[name];
4+
let s = from(component.context[name]);
55
s.take$ = n => s.take(n).forEach(_=>_)
66
return s
77
}
88

99
function historyStreamOf(component) {
10-
return getStreamOf(component, '__reactive.react.historyStream__')
10+
return getStreamOf(component, HISTORY_STREAM)
1111
}
1212

1313
function intentStreamOf(component) {
14-
return getStreamOf(component, '__reactive.react.intentStream__')
14+
return getStreamOf(component, INTENT_STREAM)
1515
}
1616

1717
function do$(listOfActions) {
1818
return from(listOfActions).forEach(x=>x())
1919
}
2020

2121
function dispatch(listOfIntent, component) {
22-
let s = intentStreamOf(component)
22+
let s = component.context[INTENT_STREAM]
2323
return from(listOfIntent).forEach(i=>s.send(i))
2424
}
2525

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"most-subject": "^5.2.0",
2929
"ramda": "^0.22.1",
3030
"react": "^15.3.2",
31-
"rx": "^4.1.0"
31+
"rxjs": "^5.0.0-rc.4"
3232
},
3333
"jest": {
3434
"moduleFileExtensions": [

yarn.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,9 +2454,11 @@ rimraf@^2.4.3, rimraf@^2.4.4, rimraf@~2.5.1, rimraf@~2.5.4, rimraf@2:
24542454
dependencies:
24552455
glob "^7.0.5"
24562456

2457-
rx@^4.1.0:
2458-
version "4.1.0"
2459-
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"
2457+
rxjs:
2458+
version "5.0.0-rc.4"
2459+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.0.0-rc.4.tgz#a4d08bc5d7f30d48ed7130e2995490c326a325c4"
2460+
dependencies:
2461+
symbol-observable "^1.0.1"
24602462

24612463
sane@~1.4.1:
24622464
version "1.4.1"
@@ -2604,7 +2606,7 @@ supports-color@^3.1.0, supports-color@^3.1.2:
26042606
dependencies:
26052607
has-flag "^1.0.0"
26062608

2607-
symbol-observable@^1.0.2:
2609+
symbol-observable@^1.0.1, symbol-observable@^1.0.2:
26082610
version "1.0.4"
26092611
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"
26102612

0 commit comments

Comments
 (0)