Skip to main contentredux-mvc

Bridge Middleware

redux-mvc allows to setup a global context that can be accessible from every other child context. It is useful to put any data or state that will be reused among contexts.

To provide the global context you must specify the contextId as the special constant GLOBAL_CONTEXT_ID:

import { createContext } from "@redux-mvc/core"
const decorate = createContext({
module,
contextId: GLOBAL_CONTEXT_ID
})

To consume state from the global context you must pass an array of namespaces to the addBridge module decorator:

import * as R from "ramda"
import { addBridge } from "@redux-mvc/core"
const newModule = R.compose(
addBridge({ trackGlobalNamespaces: [RoutingModel.namespace] })
...
)(module)
Note: The actions from the global namespace will be forwarded to the local context.

To choose what kind of actions can be dispatched to the global context you need to specify the dispatchToGlobal predicate function:

import * as R from "ramda"
import { addBridge } from "@redux-mvc/core"
const newModule = R.compose(
addBridge({
dispatchToGlobal: action => action.type === "Routing/push"
})
...
)(module)