Skip to content

Commit 33256ff

Browse files
committed
runS to update all state changes to react component
1 parent 31d0d85 commit 33256ff

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ project/plugins/project/
5050
.lib/
5151

5252
# End of https://www.gitignore.io/api/sbt
53+
examples

src/__tests__/fantasy-test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ const CounterView: React.SFC<any> = props => (
1919
</div>
2020
)
2121

22-
CounterView.defaultProps = { count: 0 }
22+
CounterView.defaultProps = { count: 0, count1: 1, count2: 0 }
2323

2424
interface Intent {
2525
type: string
2626
value?: any
2727
}
2828
interface CountProps {
2929
count: number
30+
count1: number
31+
count2: number
3032
}
3133

3234
let mountx = compose(mount, y => React.createFactory(X)({ x: rx }, y))
@@ -75,9 +77,10 @@ describe('actions', () => {
7577
describe('map', () => {
7678
beforeEach(() => {
7779
Counter = fantasyX.map(a => (
78-
{ count: (a.count || 0) * 2 }
79-
))
80-
.apply(CounterView)
80+
{ count1: (a.count1 || 1) * 2 }
81+
)).concat(fantasyX.map(a => (
82+
{ count2: (a.count2 || 0) + 2 }
83+
))).apply(CounterView)
8184

8285
counterWrapper = mountx(<Counter />)
8386
counter = counterWrapper.find(Counter).getNode()
@@ -93,7 +96,11 @@ describe('actions', () => {
9396
actions.inc,
9497
])
9598
.collect(counter)
96-
.then(x => expect(x.count).toBe(14))
99+
.then(x => {
100+
/* -(count+1) (count1*2)-(count+1) (count1*2)-(count+1) (count1*2)-> */
101+
/* -(count+1) (count2+2)-(count+1) (count2+2)-(count+1) (count2+2)-> */
102+
expect(x).toEqual({ "count": 6, "count1": 8, "count2": 6 })
103+
})
97104
})
98105
})
99106

src/fantasy/planx.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class PlanX<E extends HKTS, I, A> {
3333
(S1, S2) =>
3434
S1.chain(s1 =>
3535
S2.chain(s2 =>
36-
State.pure(f(s1, s2))
36+
State.patch<A>(() => f(s1, s2))
3737
)
3838
)
3939
, machineA.update$, machineB.update$
@@ -57,7 +57,7 @@ export class PlanX<E extends HKTS, I, A> {
5757
S1.chain(s1 =>
5858
S2.chain(s2 =>
5959
S3.chain(s3 =>
60-
State.pure(f(s1, s2, s3)))))
60+
State.patch<A>(() => f(s1, s2, s3)))))
6161
, machineA.update$, machineB.update$, machineC.update$
6262
)
6363
let actions = Object.assign({}, machineA.actions, machineB.actions, machineC.actions)
@@ -83,7 +83,7 @@ export class PlanX<E extends HKTS, I, A> {
8383
S2.chain(s2 =>
8484
S3.chain(s3 =>
8585
S4.chain(s4 =>
86-
State.pure(f(s1, s2, s3, s4))))))
86+
State.patch<A>(() => f(s1, s2, s3, s4))))))
8787
, machineA.update$, machineB.update$, machineC.update$, machineD.update$
8888
)
8989
let actions = Object.assign({}, machineA.actions, machineB.actions, machineC.actions, machineD.actions)
@@ -112,7 +112,7 @@ export class PlanX<E extends HKTS, I, A> {
112112
S3.chain(s3 =>
113113
S4.chain(s4 =>
114114
S5.chain(s5 =>
115-
State.pure(f(s1, s2, s3, s4, s5)))))))
115+
State.patch<A>(() => f(s1, s2, s3, s4, s5)))))))
116116
, machineA.update$, machineB.update$, machineC.update$, machineD.update$, machineE.update$
117117
)
118118
let actions = Object.assign({}, machineA.actions, machineB.actions, machineC.actions, machineD.actions, machineE.actions)
@@ -138,7 +138,7 @@ export class PlanX<E extends HKTS, I, A> {
138138
return new PlanX<E, I, A>(intent$ => {
139139
let machine = this.apply(intent$)
140140
let update$ = streamOps.map<StateP<A>, StateP<A>>(
141-
state => state.chain(s => State.pure(f(s))),
141+
state => state.chain(() => State.patch<A>(f)),
142142
machine.update$
143143
)
144144
return { update$, actions: machine.actions }
@@ -151,7 +151,7 @@ export class PlanX<E extends HKTS, I, A> {
151151
return new PlanX<E, I, A>(intent$ => {
152152
let machine = this.apply(intent$)
153153
let update$ = streamOps.map<StateP<A>, StateP<A>>(
154-
state => state.chain(s => State.pure(fb(s))),
154+
state => state.chain(() => State.patch<A>(fb)),
155155
machine.update$
156156
)
157157
return { update$, actions: fa(machine.actions) }
@@ -162,7 +162,7 @@ export class PlanX<E extends HKTS, I, A> {
162162
return intent$ => {
163163
let machine = this.apply(intent$)
164164
let update$ = streamOps.map<StateP<A>, Update<A>>(
165-
s => s.runA.bind(s),
165+
s => s.runS.bind(s),
166166
machine.update$
167167
)
168168
return { update$, actions: machine.actions }

0 commit comments

Comments
 (0)