Skip to content

Commit 3a1480e

Browse files
committed
fix compose test
1 parent 7da0917 commit 3a1480e

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

lib/__tests__/react-most-test.jsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,18 @@ describe('react-most', () => {
201201
let counterWrapper21 = compose(counterWrapper2)(counterWrapper)
202202
const Counter2 = counterWrapper21(CounterView)
203203
//counterWrapper2(counterWrapper(CounterView))
204-
console.log(Counter2);
205-
xit('counter add inc2, dec2', (done)=>{
204+
it('counter add inc2, dec2', ()=>{
206205
let counterWrapperr = TestUtils.renderIntoDocument(
207206
<Most engine={Engine}>
208207
<Counter2 history={true} />
209208
</Most>
210209
)
211210
let counterView = TestUtils.findRenderedComponentWithType(counterWrapperr, CounterView)
212-
/* let counter = TestUtils.findRenderedComponentWithType(counterWrapperr, Counter)*/
213211
let counter2 = TestUtils.findRenderedComponentWithType(counterWrapperr, Counter2)
214212
counterView.props.actions.inc()
215-
console.log(counterView.props.actions.inc.toString())
216-
/* counterView.props.actions.inc2()*/
217-
/* counterView.props.actions.dec()*/
218-
219-
expect(stateHistoryOf(counter2)).toBe(2)
220-
/* expect(stateHistoryOf(counter
221-
)).toBe(2)*/
222-
return intentStreamOf(counter2).take(1).observe(x=>console.log(x)).then(x=>expect(false).toBe(true)).then(done)
223-
213+
counterView.props.actions.inc2()
214+
counterView.props.actions.dec()
215+
expect(stateHistoryOf(counter2)[2].count).toBe(2)
224216
})
225217
})
226218

lib/react-most.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { PropTypes } from 'prop-types';
33
import initHistory, { Traveler } from './history';
44
import { Plan, Actions, Connect, ConnectProps, EngineSubject, Update, ConnectClass } from './interfaces'
5-
import { from, Stream, Subscription } from 'most';
5+
import { from, Stream, Subscription, mergeArray } from 'most';
66
import { Engine } from './engine/most';
77

88
// 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
@@ -24,10 +24,9 @@ export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (Wra
2424
static displayName = connectDisplayName
2525
constructor(props, context) {
2626
super(props, context);
27-
let { actions, update$ } = main(context[REACT_MOST_ENGINE].historyStream, props)
28-
let { actions: preActions, update$: preUpdates } = this.main(context[REACT_MOST_ENGINE].historyStream, props)
29-
this.update$ = preUpdates ? update$.merge(preUpdates) : update$
30-
this.actions = Object.assign({}, bindActions(actions, context[REACT_MOST_ENGINE].intentStream, this), preActions);
27+
let { actions, update$ } = main(context[REACT_MOST_ENGINE].intentStream, props)
28+
this.update$ = this.update$.merge(update$)
29+
this.actions = Object.assign({}, bindActions(actions, context[REACT_MOST_ENGINE].intentStream, this), this.actions);
3130
}
3231
}
3332
} else {
@@ -48,10 +47,9 @@ export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (Wra
4847
return this.setState(state);
4948
});
5049
}
51-
this.main = main
52-
let { actions, update$ } = main(context[REACT_MOST_ENGINE].intentStream, props)
53-
this.update$ = props.update$ ? props.update$.merge(update$) : update$
54-
this.actions = Object.assign({}, bindActions(actions, context[REACT_MOST_ENGINE].intentStream, this), props.actions);
50+
let { actions, update$ } = main(engine.intentStream, props)
51+
this.actions = bindActions(actions, engine.intentStream, this)
52+
this.update$ = update$
5553
let defaultKey = Object.keys(WrappedComponent.defaultProps);
5654
this.state = Object.assign(
5755
{},

0 commit comments

Comments
 (0)