All Projects → stutrek → cross-tab-middleware

stutrek / cross-tab-middleware

Licence: other
Redux middleware for sending actions across open browser tabs

Programming Languages

javascript
184084 projects - #8 most used programming language

cross-tab-middleware

This is middleware that lets you opt in to sending actions across open browser tabs using cross-tab-channel.

Usage

1. Add it to your store

Pass crossTabMiddleware a string to identify and/or version your app.

Same Domain

import crossTabMiddleware from 'cross-tab-middleware';

store = createStore(
    reducer,
    applyMiddleware(
        thunk,
        createdRouterMiddleware,
        promiseMiddleware(),
        crossTabMiddleware('your-app-name')
    )
);

Cross Domain

To work across different domains, cross-tab-channel uses an iframe. That HTML file is entirely self contained and can be found in the cross-tab-channel repo. It has no requirements and can be hosted statically.

import crossTabMiddleware from 'cross-tab-middleware/crossDomain';

store = createStore(
    reducer,
    applyMiddleware(
        thunk,
        createdRouterMiddleware,
        promiseMiddleware(),
        crossTabMiddleware('//your-domain/path/to/iframe.html', 'your-app-name')
    )
);

2. Add crossTab: true to your actions

Let the middleware know you want this action to be sent to other tabs.

export function loadUser () {
    return {
        type: USER_LOAD,
        meta: {
            crossTab: true
        },
        payload: {
            promise: userService.load()
        }
    };
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].