rs

redux-socket

redux socket request-response middleware

Showing:

Popularity

Downloads/wk

25

GitHub Stars

11

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.8KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Redux-socket

a redux middleware that allows you to trigger a socket request on the client-side and dispatch an action in response. For it's server-side counterpart, check out redux-socket-create-listeners.

If you want to trigger redux-socket, add a property named "sock" to your action, like this:

export function login(username, password) {
    return {
        sock: {
            path: 'login',
            data: { username, password },
            // the following are the actionCreators that get
            // fired when the server issues a response,
            success: authSuccess,
            failure: notify,
        },
    };
}

If a 'type' parameter isn't specified by the response actionCreators (success and failure), the sock's path (in this case 'login') will be assigned. This way you can use a single isomorphic reducer to keep your redux store state in session, for example, as well as on the client side. For more information about this, check out redux-socket-create-listeners.

To initlialize the middleware, you'll need to have already created the socket and to pass it as an argument, like so:

const sockMiddleware = sockMiddlewareCreator(
    socket, disconnectedAction, duplicateAction);

DisconnectedAction and duplicateAction are actions to be dispatched in case the socket is disconnected, or a listener is already active on that socket. These are optional so if you leave them blank it'll just log to the console.

Installation

npm install -S redux-socket

Example usage

createMiddleware Actions

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100