pubSub.DataPubSubSystem - ZeMA-gGmbH/NoPE-JS GitHub Wiki
pubSub.DataPubSubSystem
Default implementation of IDataPubSubSystem
Extends the PubSubSystem by adding the following properties and methods:
-
pushDatato push data into the system. -
pullDatato pull data from the system. Will allways return the current data or the default value if no data is present at the given path. -
patternbasedPullDatato pull data with a given pattern. See the example for details. -
patternBasedPushto push data with a given pattern into the system. - If you want to acces the root data please check the property
datawhich will contain the entire data root that has been created.
-
PubSubSystem<ITopicSetContentOptions,INopeObservable,INopeTopicWithDirectAccess>↳
DataPubSubSystem
new DataPubSubSystem(options?)
| Name | Type |
|---|---|
options |
Partial<IPubSubOptions> & { generateEmitterType?: () => INopeObservable<any, any, any, IEventAdditionalData> } |
_options: IPubSubOptions
Readonly onIncrementalDataChange: INopeEventEmitter<IIncrementalChange, IIncrementalChange, IIncrementalChange, IEventAdditionalData>
An observable which holds the incremental data change. this will be triggered, if the an emitter (publisher) changes its data. Contains only the last emitted data and the topic
// Describe the required Test:
let pubSubSystem = new PubSubSystemBase({
generateEmitterType: function () {
return new NopeEventEmitter() as INopeEventEmitter;
},
});
// Create a Publisher for the system:
let publisher: INopeEventEmitter = new NopeEventEmitter();
pubSubSystem.register(publisher, {
mode: "publish",
schema: {},
topic: "this/is/a/test",
});
pubSubSystem.onIncrementalDataChange.subscribe(console.log);
publisher.emit("Hello World!"); // Logs the following => {path: "this/is/a/test", data: "Hello World!"}Author
M.Karkowski
Memberof
IPubSubSystem
IDataPubSubSystem.onIncrementalDataChange
PubSubSystem.onIncrementalDataChange
Readonly publishers: IMapBasedMergeData<INopeTopicWithDirectAccess<any, any, any>, IPubSubEmitterOptions<ITopicSetContentOptions>, INopeTopicWithDirectAccess<any, any, any>, string>
List containing all publishers.
Author
M.Karkowski
Memberof
IPubSubSystem
Readonly subscriptions: IMapBasedMergeData<INopeTopicWithDirectAccess<any, any, any>, IPubSubEmitterOptions<ITopicSetContentOptions>, INopeTopicWithDirectAccess<any, any, any>, string>
List, containing all subscribers.
Author
M.Karkowski
Memberof
IPubSubSystem
IDataPubSubSystem.subscriptions
get data(): unknown
A Getter to return a COPY of the item. Outside of the system, you'll never receive the original object. It is allways a clone.
Author
M.Karkowski
Memberof
PubSubSystemBase
unknown
get emitters(): Object
List all known Emitters in the System.
Object
| Name | Type |
|---|---|
publishers |
{ name: string ; schema: INopeDescriptor }[] |
subscribers |
{ name: string ; schema: INopeDescriptor }[] |
PubSubSystemBase.emitters
get options(): IPubSubOptions
Options which describe the Behavior
Author
M.Karkowski
Memberof
IPubSubSystem
PubSubSystemBase.options
dispose(): void
Unregisters all Emitters and removes all subscriptions of the "onIncrementalDataChange", "publishers" and "subscriptions"
Author
M.Karkowski
Memberof
PubSubSystemBase
void
emit(eventName, data, options?): void
Emits an Events and all subscribes, where the pattern matches will be informed
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
eventName |
string |
The Topic. |
data |
any |
The Data of the Event. |
options? |
ITopicSetContentOptions |
void
patternBasedPush<T>(pattern, data, options?, fast?): void
Option to push data to the system using a pattern see patternBasedPush @ IDataPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
| Name | Type | Default value | Description |
|---|---|---|---|
pattern |
string |
undefined |
The pattern (see pubSub) |
data |
T |
undefined |
The data to push |
options |
Partial<IEventAdditionalData> |
{} |
The options used during pushing the data (see IEventAdditionalData) |
fast |
boolean |
false |
If enabled, firstly, the data is pushed, afterwards, we just inform once. |
void
Nothing
IDataPubSubSystem.patternBasedPush
patternbasedPullData<T, D>(pattern, _default?): { data: T ; path: string }[]
Option to pull data from the system with a pattern see patternbasedPullData @ IDataPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
D |
null |
| Name | Type | Default value | Description |
|---|---|---|---|
pattern |
string |
undefined |
The pattern (see pubSub) |
_default |
D |
null |
The Default object, if data is not present. |
{ data: T ; path: string }[]
IDataPubSubSystem.patternbasedPullData
pullData<T, D>(topic, _default?): T
Option to pull data from the system see pullData @ IDataPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
D |
null |
| Name | Type | Default value | Description |
|---|---|---|---|
topic |
string |
undefined |
the Topic to use. |
_default |
D |
null |
The default object, if nothing else is provided |
T
The data. Defined as T
pushData<T>(path, content, options?): void
Option to push data into the system see pushData @ IDataPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
| Name | Type | Description |
|---|---|---|
path |
string |
The path of the data. |
content |
T |
The content of the Data. |
options |
Partial<IEventAdditionalData> |
The options used during pushing the data (see IEventAdditionalData) |
void
nothing.
register(emitter, options): INopeTopicWithDirectAccess<any, any, any>
Function to register an Observable. Please define the Options, to decide whether the data of the observable should be published or subscribed.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
emitter |
INopeObservable<any, any, any, IEventAdditionalData> |
The Emitter to consider |
options |
IEventOptions |
INopeTopicWithDirectAccess<any, any, any>
{O}
registerSubscription<T>(topic, subscription): INopeObserver
A Helper, that allows the user to subscribe to changes. Therfore he must transmit
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
T |
unknown |
Expected Type of the content |
| Name | Type | Description |
|---|---|---|
topic |
string |
The |
subscription |
IEventCallback<T, ITopicSetContentOptions> |
{INopeObserver}
IDataPubSubSystem.registerSubscription
PubSubSystem.registerSubscription
toDescription(): Object
Describes the Data.
Object
| Name | Type |
|---|---|
data |
unknown |
publishers |
{ name: string ; schema: INopeDescriptor }[] |
subscribers |
{ name: string ; schema: INopeDescriptor }[] |
IDataPubSubSystem.toDescription
unregister(emitter): boolean
Removes an observable of the Pub-Sub-System.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type |
|---|---|
emitter |
INopeObservable<any, any, any, IEventAdditionalData> |
boolean
{boolean}
updateMatching(): void
Internal Match-Making Algorithm. This allowes to Create a predefined List between Publishers and Subscribers. Thereby the Process is speed up, by utilizing this Look-Up-Table
Author
M.Karkowski
Memberof
PubSubSystemBase
void
IDataPubSubSystem.updateMatching
updateOptions(emitter, options): void
Function to update the options and there by the topics of an observable.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
emitter |
INopeObservable<any, any, any, IEventAdditionalData> |
The Emitter to consider |
options |
IEventOptions |
The modified options |
void