Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const horeducer = (callback,...reducers) => (state, action) => {
- var fnamed ={}
- reducers.map( r => fnamed[r.name]=s=> r(s,action) )
- return callback(state,action,fnamed)
- }
- const red1 = (state=0,action) =>{
- console.log("r1state");
- console.log(state)
- switch(action){
- case 'INC':
- return state+1
- case 'DEC':
- return state+1
- default:
- return state
- }
- }
- var state1;
- console.log(red1(state1,'INC'))
- const red2 = (state={a:0},action) =>{
- switch(action){
- case 'ADD2':
- state.a+=2
- return state
- default:
- state
- }
- }
- var state2;
- console.log(red2(state2,'ADD2'))
- const hored = (state, action, reducers) => {
- console.log(reducers[0](state))
- var s = {a:reducers[0](state)}
- return reducers[1](s)
- }
- const hored2= (state, action, {red1,red2}) => {
- console.log(red1(state))
- var s = {a:red1(state)}
- return red2(s)
- }
- var x = horeducer(hored2,red1,red2)
- console.log(x(1,'ADD2'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement