Skip to content

Commit f70d8b2

Browse files
committed
add send method to Stream
1 parent 58c8c7a commit f70d8b2

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

benchmark/react-most-pref.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ var todolist;
77
var context = Most.prototype.getChildContext()
88
var most = require('most');
99
var log = _=>console.log(_)
10-
var addToIntentStream = context["__reactive.react.addToIntentStream__"]
1110
var intentStream = context["__reactive.react.intentStream__"]
1211
function genActions(intent$){
1312
var add$ = intent$.filter(x=>x.type=='add')
@@ -24,9 +23,6 @@ function genActions(intent$){
2423
}
2524

2625
var actions = genActions(intentStream);
27-
for(var i=0;i<CYCLE;i++){
28-
addToIntentStream(actions.add(i))
29-
}
3026
var state={value:0}
3127
actions.addState$.observe(mapper=>{
3228
state=mapper(state);
@@ -40,6 +36,10 @@ actions.addState$.observe(mapper=>{
4036
}
4137
})
4238

39+
for(var i=0;i<CYCLE;i++){
40+
intentStream.send(actions.add(i))
41+
}
42+
4343
/**
4444
Memory Usage Before: { rss: 32501760, heapTotal: 16486912, heapUsed: 11307128 }
4545
Memory Usage After: { rss: 34418688, heapTotal: 18550784, heapUsed: 11932336 }

lib/engine/most.es6

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ export default function mostEngine() {
66
let intentStream = most.create(add => {
77
addToIntentStream = add;
88
return function dispose(e){
9-
addToIntentStream = id;
9+
addToIntentStream = null;
1010
console.log('action stream disposed');
1111
}
1212
});
1313
intentStream.drain();
14+
intentStream.send = addToIntentStream;
1415
let addToHistoryStream = function(){
1516
console.error('history stream not binded');
1617
};
1718
let historyStream = most.create(add => {
1819
addToHistoryStream = add;
1920
return function dispose(e){
20-
addToHistoryStream = id;
21+
addToHistoryStream = null;
2122
console.log('history stream disposed');
2223
}
2324
});
2425
historyStream.drain();
25-
26+
historyStream.send = addToHistoryStream;
2627
function flatObserve(actionsSinks, f){
2728
return most.from(actionsSinks).join().observe(f);
2829
}
2930

30-
return {intentStream, addToIntentStream, flatObserve, historyStream, addToHistoryStream}
31+
return {intentStream, flatObserve, historyStream}
3132
}

lib/react-most.es6

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ import React from 'react'
22
import mostEngine from './engine/most'
33
// 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
44
const intentStream = "__reactive.react.intentStream__";
5-
const addToIntentStream = "__reactive.react.addToIntentStream__";
65
const historyStream = "__reactive.react.historyStream__";
7-
const addToHistoryStream = "__reactive.react.addToHistoryStream__";
86
const flatObserve = "__reactive.react.flatObserve__";
97

108
const CONTEXT_TYPE = {
119
[intentStream]: React.PropTypes.object,
12-
[addToIntentStream]: React.PropTypes.func,
1310
[historyStream]: React.PropTypes.object,
14-
[addToHistoryStream]: React.PropTypes.func,
1511
[flatObserve]: React.PropTypes.func,
1612
}
1713

@@ -43,14 +39,15 @@ export function connect(main, initprops={}) {
4339
if(observable(sinks[name]))
4440
actionsSinks.push(sinks[name]);
4541
else if(sinks[name] instanceof Function){
46-
this.actions[name] = (...args)=>this.context[addToIntentStream](sinks[name].apply(null, args));
42+
this.actions[name] = (...args)=>this.context[intentStream].send(sinks[name].apply(null, args));
4743
}
4844
}
4945
this.context[flatObserve](actionsSinks, (action)=>{
5046
if(action instanceof Function)
5147
this.setState((prevState, props)=>{
5248
let newState = action.call(this, prevState,props);
53-
this.context[addToHistoryStream](prevState);
49+
if(initprops.history)
50+
this.context[historyStream].send(prevState);
5451
return newState;
5552
});
5653
else
@@ -78,10 +75,8 @@ let Most = React.createClass({
7875

7976
return {
8077
[intentStream]: engine.intentStream,
81-
[addToIntentStream]: engine.addToIntentStream,
8278
[flatObserve]: engine.flatObserve,
8379
[historyStream]: engine.historyStream,
84-
[addToHistoryStream]: engine.addToHistoryStream,
8580
}
8681
},
8782
render(){

0 commit comments

Comments
 (0)