Skip to content

Commit 7da0917

Browse files
committed
es5 mixing style instead of HoC
1 parent 8b29628 commit 7da0917

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

lib/__tests__/react-most-test.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ describe('react-most', () => {
200200
})
201201
let counterWrapper21 = compose(counterWrapper2)(counterWrapper)
202202
const Counter2 = counterWrapper21(CounterView)
203+
//counterWrapper2(counterWrapper(CounterView))
204+
console.log(Counter2);
203205
xit('counter add inc2, dec2', (done)=>{
204206
let counterWrapperr = TestUtils.renderIntoDocument(
205207
<Most engine={Engine}>

lib/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class Connect<I, S> extends React.PureComponent<ConnectProps<I>, S> {
2828
}
2929

3030
export interface ConnectClass<I, S> {
31+
contextTypes?: any
32+
defaultProps?: any
3133
new (props?: ConnectProps<I>, context?: any): Connect<I, S>;
3234
}
3335

lib/react-most.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,21 @@ const CONTEXT_TYPE = {
1313
};
1414

1515
export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (WrappedComponent: React.ComponentClass<any>) => ConnectClass<I, S> {
16-
return function(WrappedComponent: React.ComponentClass<any>) {
16+
return function(WrappedComponent: ConnectClass<I, S>) {
1717
let connectDisplayName = `Connect(${getDisplayName(WrappedComponent)})`;
1818
if (WrappedComponent.contextTypes === CONTEXT_TYPE) {
19-
return class ConnectNode extends Connect<I, S>{
19+
return class ConnectNode extends WrappedComponent {
2020
actions: Actions<I>
2121
update$: Stream<Update<S>>
22+
main: Plan<I, S>
2223
static contextTypes = CONTEXT_TYPE
2324
static displayName = connectDisplayName
2425
constructor(props, context) {
2526
super(props, context);
2627
let { actions, update$ } = main(context[REACT_MOST_ENGINE].historyStream, props)
27-
this.update$ = props.update$ ? update$.merge(props.update$) : update$
28-
this.actions = Object.assign({}, bindActions(actions, context[REACT_MOST_ENGINE].intentStream, this), props.actions);
29-
}
30-
render() {
31-
return h(
32-
WrappedComponent,
33-
Object.assign({}, opts, this.props, {
34-
update$: this.update$,
35-
actions: this.actions,
36-
})
37-
);
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);
3831
}
3932
}
4033
} else {
@@ -43,6 +36,7 @@ export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (Wra
4336
update$: Stream<Update<S>>
4437
traveler: Traveler<S>
4538
subscription: Subscription<S>
39+
main: Plan<I, S>
4640
static contextTypes = CONTEXT_TYPE
4741
static displayName = connectDisplayName
4842
constructor(props, context) {
@@ -54,7 +48,7 @@ export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (Wra
5448
return this.setState(state);
5549
});
5650
}
57-
51+
this.main = main
5852
let { actions, update$ } = main(context[REACT_MOST_ENGINE].intentStream, props)
5953
this.update$ = props.update$ ? props.update$.merge(update$) : update$
6054
this.actions = Object.assign({}, bindActions(actions, context[REACT_MOST_ENGINE].intentStream, this), props.actions);

0 commit comments

Comments
 (0)