createNamespace
function createNamespace(namespace): Namespace;Namespaced factories, so two independently deployed apps on one origin cannot collide by both taking the defaults.
Bare names are the problem this solves. A BroadcastChannel is global to the
origin, so a name is an identity — and two micro-frontends that each call
createSharedStore('cart', …), or each omit the name and land on
DEFAULT_NAME, are not two carts. They are one cart, with two teams
writing to it, one leader seat contended between them, and one presence roster
counting both. Nothing warns, because from the library’s side it looks exactly
like the intended case of two tabs sharing state.
“Prefix your names” is the workaround, and it fails the way conventions fail: silently, once, in whichever app forgot.
const checkout = createNamespace('checkout');const cart = checkout.createSharedStore('cart', { items: [] }); // bus "checkout:cart"const events = checkout.createChannel('events'); // bus "checkout:events"What it is not
Section titled “What it is not”Not a security boundary. Everything here is same-origin and a namespace is a string, so anything on the page can construct the same one deliberately. It prevents collision, not access — see the security model docs.
Not related to wire.scope, which says which engine a wire belongs to, or
to the React package’s share scope, which says how far a value travels.
Three different axes; this is the one about names.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
namespace | string |