redux-saga-routines
redux-saga-routines copied to clipboard
createRoutines?
I think it would be nice to have createRoutines
method, like createActions
in 'redux-actions', to create routines in batch, and not one by one
@victordidenko good idea! PR are welcome :)
Made an PR #38, first approach (don't like very much), to hear your opinion
Proposals
Nested example:
const routines = createRoutines({ people: { search: name => ({ name }) } });
routines.people.search('Ada');
// { type: 'routines/people/search/TRIGGER', payload: { name: 'Ada' } }
We can access to the stage with underscore prefix and for example to overwrite the default payloadCreator:
const routines = createRoutines({
people: {
search: {
_TRIGGER: ({ phone }) => parseInt(phone, 2)
},
add: null // maybe as well or something other to say `default`,
remove: null
}
});
routines.people.search({ name: 'Ada', phone: 010010 });
// { type: 'routines/people/search/TRIGGER', payload: 42 }
Or add custom routines with createRoutineCreator
:
const routines = createRoutines({
people: {
search: {
more_info: {
_OPEN: null,
_HIDE: null,
}
}
}
});
routines.people.search.moreInfo.open({ id: 42 });
// { type: 'routines/people/search/OPEN', payload: { id: 42 } }
routines.people.search.moreInfo.hide({ id: 42 });
// { type: 'routines/people/search/HIDE', payload: { id: 42 } }
And maybe even create extended routines with default stages and like in that package
I think to implement that. Not sure how long that it takes, hope I will provide some first version soon.
Not sure about underscore before the stage (for example _TRIGGER) And now I realise that maybe better is to implement that in my package, because I will definitely need createCustomRoutine functionality inside createRoutines.
Today I will release the first version.
Here is createRoutines
first version https://github.com/shapkarin/extend-saga-routines#create-routines