Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1508f6e

Browse files
committed
pass all arguments to inner reducers
1 parent1a4e9a8 commit1508f6e

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

‎index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var createMachine = function(reducersObject) {
77
if(!reducer){
88
thrownewError('reducersObject missing reducer for status '+status)
99
}
10-
constnextState=reducer(state,action)
10+
constnextState=reducer.apply(undefined,arguments);
1111
if(nextState===state){
1212
returnstate
1313
}

‎test.js‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ test('should transition between states', t => {
6969
},'Should set initial status to "INIT"')
7070

7171
action('DUMMY AGAIN')
72-
7372
t.equals(state,prevState,'Should not change the state when an action is unhandled')
7473

7574
action('FETCH_USERS_RESPONSE',{users})
@@ -106,6 +105,62 @@ test('should transition between states', t => {
106105
t.end()
107106
})
108107

108+
test('should pass all arguments to inner reducers',t=>{
109+
constconfigReducer=(state={},action)=>state;
110+
constgameReducer=(state={},action,isMuted)=>{
111+
switch(action.type){
112+
case'START':
113+
constaudio=(isMuted===true) ?'OFF' :'ON'
114+
returnObject.assign({},state,{
115+
audio:audio
116+
})
117+
default:
118+
returnstate
119+
}
120+
}
121+
constinnerReducer=(state={},action)=>{
122+
constisMuted=state.config ?state.config.isMuted :undefined
123+
return{
124+
'game':gameReducer(state.game,action,isMuted),
125+
'config':configReducer(state.config,action)
126+
}
127+
}
128+
constfsmReducer=createMachine({
129+
'INIT':innerReducer
130+
});
131+
conststore=createStore(fsmReducer,undefined)
132+
store.dispatch({
133+
type:'START'
134+
})
135+
t.deepEquals(store.getState(),{
136+
status:'INIT',
137+
game:{
138+
audio:'ON'
139+
},
140+
config:{}
141+
},'Should turn game audio "ON" if isMuted !== true')
142+
143+
constsilentStore=createStore(fsmReducer,{
144+
config:{
145+
isMuted:true
146+
}
147+
})
148+
silentStore.dispatch({
149+
type:'START'
150+
})
151+
t.deepEquals(silentStore.getState(),{
152+
status:'INIT',
153+
game:{
154+
audio:'OFF'
155+
},
156+
config:{
157+
isMuted:true
158+
}
159+
},'Should turn game audio "OFF" if isMuted === true')
160+
161+
t.end()
162+
})
163+
109164
test('should error on status not found',t=>{
110165
letstore={status:'STATUS_NOT_IN_CREATE_MACHINE'}
111166
constreducer=createMachine({})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp