Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch the same action type #67

Open
YaaMe opened this issue Mar 31, 2018 · 0 comments
Open

dispatch the same action type #67

YaaMe opened this issue Mar 31, 2018 · 0 comments

Comments

@YaaMe
Copy link

YaaMe commented Mar 31, 2018

about this code:

https://github.com/lelandrichardson/redux-pack/blob/master/src/middleware.js#L41

I think it is not friendly to other middleware.
consider about this case.
I try to storage the response data after user click login.
here's a middleware

export const storageMiddleware = store => next => action => {
    switch (action.type) {
        case USER_ACTION.LOGIN: filterPack(action, () => storage(STORAGE_KEY.USER, action)); break;
        case USER_ACTION.LOGOUT: clear(STORAGE_KEY.USER); break;
        default: ;
    }
    return next(action)
}

It is confuse about filterPack
we get 2 actions which type = LOGIN but actually different.
so I have to write these code to judge request success or not.

export const filterPack = (action, callback, status = LIFECYCLE.SUCCESS) => {
    const { meta } = action;
    const lifecycle = meta ? meta[KEY.LIFECYCLE] : null;
    if (lifecycle === status) {
        return callback(meta);
    }
    return action;
}

It should be part of this repo and It seems like how your handle works in reducer.
So i guess you miss something here.

In fact, i hope it will be auto splited into ${action.type}_${lifecycle.toUpperCase()} and config it in createMiddleware

(thanks for reading :> )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant