Symbiote.js
Get startedTemplatesPropertiesAttributesFlagsContextLifecycleList itemsStylingSSRRoutingPubSubEcosystemLive examples

PubSub

PubSub - is a main Symbiote.js entity to manipulate application data. It implements simple and well known Publication-subscribe pattern and represents all you need to organize data-flow inside your components and outside of them. It is integrated to the Symbiote base class, but also can be used separately:

import { PubSub } from '@symbiotejs/symbiote';

let myDataCtx = PubSub.registerCtx({
  myProp: 'some value',
  myOtherProp: 'some other value',
});

Static methods

PubSub.registerCtx()

Use to create and register the PubSub instance.

Syntax:

registerCtx(schema)
registerCtx(schema, id)

// > PubSub instance
ArgumentType?Description
schemaObject<string, *>requiredProperty map
idString | SymboloptionalContext ID

Example:

let myDataCtx = PubSub.registerCtx({
  myProp: 'some value',
  myOtherProp: 'some other value',
}, 'MY_CTX_ID');

PubSub.getCtx()

Use to get PubSub object from registry.

Syntax:

getCtx(id)

// > PubSub instance
ArgumentType?Description
idString | SymbolrequiredContext ID

Example:

let myDataCtx = PubSub.getCtx('MY_CTX_ID');

PubSub.deleteCtx()

Use to remove PubSub object from the registry and to clear memory.

Syntax:

deleteCtx(id)
ArgumentType?Description
idString | SymbolrequiredContext ID

Example:

PubSub.deleteCtx('MY_CTX_ID');

Instance methods

pub()

Use to publish new the new property value.

Syntax:

pub(propertyKey, newValue)
ArgumentType?Description
propertyKeyStringrequiredProperty name
newValue*requiredProperty value

Example:

myDataCtx.pub('propertyName', 'newValue');

multiPub()

Use to publish multiple changes at once.

Syntax:

multiPub(propertyMap)
ArgumentType?Description
propertyMapObject<string, *>requiredKey/value update map

Example:

myDataCtx.multiPub({
  propertyName: 'new value',
  otherPropertyName: 'other new value',
});

sub()

Use to subscribe on property changes.

Syntax:

sub(propertyName, handler)
ArgumentType?Description
propertyNameStringrequiredProperty name
handler(newValue) => voidrequiredProperty update handler

Example:

myDataCtx.sub('propertyName', (newValue) => {
  console.log(newValue);
});

read()

Use to read the property value.

Syntax:

read(propertyName)

// > *
ArgumentType?Description
propertyNameStringrequiredProperty name

Example:

myDataCtx.read('propertyName');

has()

Use to check that property exists.

Syntax:

has(propertyName)

// > true / false
ArgumentType?Description
propertyNameStringrequiredProperty name

Example:

myDataCtx.has('propertyName');

add()

Use to add a new property into the existing PubSub object.

Syntax:

add(propertyName, initValue)
ArgumentType?Description
propertyNameStringrequiredProperty name
initValue*requiredInitial property value

Example:

myDataCtx.add('propertyName', 'init value');

notify()

Use for the manual invocation of the all subscription handlers for the property.

Syntax:

notify(propertyName)
ArgumentType?Description
propertyNameStringrequiredProperty name

Example:

myDataCtx.notify('propertyName');

Proceed to Biome

11.12.2025
JSDA is very simple
Why JSDA is the best way to build web apps
28.09.2024
It was really possible?
Symbiote.js as an answer to many questions
17.09.2024
Smart HTML-tags
Simple recipe with the Artificial Intelligence
25.01.2024
Symbiote VS Lit
David and Goliath: differences, pros and cons...
18.01.2024
Symbiote.js 2.x
The new major version is released. Let's see what's new...
RND-PRO.com © 2025