redux-preboiled
redux-preboiled copied to clipboard
I have a few suggestions
Hi, @denisw ! First of all, great lib!
I have a couple suggestions. Just wanted to know if you are interesting in any of them )).
Add payload creator option to createAction#withPayload
, for custom arguments in generated action creator. Also maybe add helpers like withMeta
, error
for FSA compabillity.
Create some form of middleware generator, with ho-functions mapped to corresponding action type. In my projects I'm using this construction:
declare function middlewareMappedByActions(): {
onAction<T, A>(action: { type: T; (...args: any[]): A; }, middleware: (store: Store, next, action: A) => any): this;
map(): (store: Store) => (next) => (action) => any;
};
declare function middleBefore<A>(middle: (store: Store, action: A) => any): (store: Store, next, action: A) => any;
middlewareMappedByActions()
.onAction(actions.setHostStatus, middleBefore((store, action) => {
// do staff
})
.map()
Hi @anion155! Thanks a lot for you for taking the time for making these suggestions. 🙂
Add payload creator option to
createAction#withPayload
, for custom arguments in generated action creator. Also maybe add helpers likewithMeta
,error
for FSA compabillity.
Good idea! I was already considering that, but just didn't get around to it yet. Out of curiosity, are there any particular use cases you have for action metadata and/or the error
flag?
Create some form of middleware generator, with ho-functions mapped to corresponding action type. In my projects I'm using this construction:
declare function middlewareMappedByActions(): { onAction<T, A>(action: { type: T; (...args: any[]): A; }, middleware: (store: Store, next, action: A) => any): this; map(): (store: Store) => (next) => (action) => any; }; declare function middleBefore<A>(middle: (store: Store, action: A) => any): (store: Store, next, action: A) => any; middlewareMappedByActions() .onAction(actions.setHostStatus, middleBefore((store, action) => { // do staff }) .map()
I'm interested in learning more about how you use this. Do you have some examples where this helper was useful for you?
Out of curiosity, are there any particular use cases you have for action metadata and/or the error flag?
Not yet, sometimes it can used, but for me it was two or three this kind of actions, and in all my cases it's all was handled by middleware, 'cause I don't really like to store object like error or some mythic-non-typed meta information in store. But FSA is kind of standart already, and some people may found some good use for this.
I'm interested in learning more about how you use this. Do you have some examples where this helper was useful for you?
For the middleBefore
, it is just shortcut for:
store => next => action => {
// do staff
return next(action);
}
Similar middleAfter
:
store => next => action => {
const result = next(action);
// do staff
return result;
}
For the middlewareMappedByActions
, I think it's common case for middlewares that do staff on some types of action:
store => next => action =. {
switch (action.type) {
case 'SOME_AWESOME_ACTION_TYPE':
// do staff
return next(action);
}
}
Helper just creates map of handlers, and map
method returns middleware it self. I'm using it simple middleware declarations like export default middlewareMappedByActions...
. All helpers returns currying functions.