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

Commit8ae858f

Browse files
zhoudxnzdanzGentrack
authored andcommitted
Accept one extra argument/update document
1 parent1508f6e commit8ae858f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ const fetchUsersReducer = (state, action) => {
9898

9999
The (marginal) advantages of using redux-machine over just using the FSM pattern is that you can more clearly express intent and write slightly less code.
100100

101+
##Supporting an Extra Argument
102+
redux-machine supports to passing an extra argument to state reducers, for cases where a state reducer requires a third argument for other state it dpeneds on.
103+
101104
##Asynchronous Effects
102105

103106
redux-machine doesn't prescribe a way of handling asynchronous effects such as API calls. This leaves it open for you to use[no async effects library](http://stackoverflow.com/a/34599594/2482570),[redux-loop](https://github.com/redux-loop/redux-loop),[redux-thunk](https://github.com/gaearon/redux-thunk),[redux-saga](https://github.com/yelouafi/redux-saga),[redux-funk](https://github.com/mheiber/redux-funk) or[anything else](https://github.com/markerikson/redux-ecosystem-links/blob/master/side-effects.md).

‎index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use strict"
22

33
varcreateMachine=function(reducersObject){
4-
returnfunction(state,action){
4+
returnfunction(state,action,extraArgument){
55
varstatus=(state&&state.status) ?state.status :'INIT'
66
varreducer=reducersObject[status]
77
if(!reducer){
88
thrownewError('reducersObject missing reducer for status '+status)
99
}
10-
constnextState=reducer.apply(undefined,arguments);
10+
constnextState=reducer(state,action,extraArgument)
1111
if(nextState===state){
1212
returnstate
1313
}

‎test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test('should transition between states', t => {
105105
t.end()
106106
})
107107

108-
test('should passall arguments to inner reducers',t=>{
108+
test('shouldbe able topassan extraArgument to inner reducers',t=>{
109109
constconfigReducer=(state={},action)=>state;
110110
constgameReducer=(state={},action,isMuted)=>{
111111
switch(action.type){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp