types.nope.IDataPubSubSystem - ZeMA-gGmbH/NoPE-JS GitHub Wiki
A data-based Publish and Subscribe system. Extends IPubSubSystem by providing the the methods and properties:
-
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.
Author
M.Karkowski
Export
| Name | Type |
|---|---|
AD |
extends ITopicSetContentOptions = ITopicSetContentOptions
|
I |
extends INopeObservable<unknown, unknown, unknown, AD> = INopeObservable<unknown, unknown, unknown, AD> |
O |
extends INopeTopicWithDirectAccess = INopeTopicWithDirectAccess
|
-
IPubSubSystem<AD,I,O>↳
IDataPubSubSystem
Readonly data: unknown
A Getter to return a COPY of the item. Outside of the system, you'll never receive the original object.
Author
M.Karkowski
Memberof
IPubSubSystem
Readonly emitters: Object
List all known Emitters in the System.
| Name | Type |
|---|---|
publishers |
{ name: string ; schema: INopeDescriptor }[] |
subscribers |
{ name: string ; schema: INopeDescriptor }[] |
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
IPubSubSystem.onIncrementalDataChange
Readonly options: IPubSubOptions
Options which describe the Behavior
Author
M.Karkowski
Memberof
IPubSubSystem
Readonly publishers: IMapBasedMergeData<O, IPubSubEmitterOptions<AD>, O, string>
List containing all publishers.
Author
M.Karkowski
Memberof
IPubSubSystem
Readonly subscriptions: IMapBasedMergeData<O, IPubSubEmitterOptions<AD>, O, string>
List, containing all subscribers.
Author
M.Karkowski
Memberof
IPubSubSystem
dispose(): void
Disposes the Pub-Sub-System.
Author
M.Karkowski
Memberof
IPubSubSystem
void
emit(path, data, options?): void
Emits an Events and all subscribes, where the pattern matches will be informed
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
path |
string |
The Topic. |
data |
any |
The Data of the Event. |
options? |
Partial<AD> |
void
patternBasedPush<T>(pattern, content, options): void
Pushes data to the elements, where the pattern matches.
Author
M.Karkowski
Memberof
IDataPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
| Name | Type | Description |
|---|---|---|
pattern |
string |
The pattern, which should be used to forward the data. For valid patterns see pattern |
content |
T |
The content to store in the given path. |
options |
Partial<IEventAdditionalData> |
void
patternbasedPullData<T, D>(pattern, _default): { data: T ; path: string }[]
A Pattern based Pull. You can provide a mqtt based pattern and receive an array which contains all the data which matches the topic.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type |
|---|---|
T |
unknown |
D |
null |
| Name | Type | Description |
|---|---|---|
pattern |
string |
The pattern to pull the data from |
_default |
D |
a default value, o |
{ data: T ; path: string }[]
{{ path: string, data: T }[]}
pullData<T, D>(path, _default): T
Pull some Data of System. You will allways receive a just a copy. This method prevents you to use a pattern like path. If you want to use patterns please use the "patternbasedPullData"
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
T |
unknown |
Expected Type of the return. Defaults to unkown |
D |
null |
Default Value. |
| Name | Type | Description |
|---|---|---|
path |
string |
|
_default |
D |
If no data is found => return the default data. |
T
The Expected Type
pushData<T>(path, content, options?): void
Function, to push data. Every subscriber will be informed, if pushing the data on the given path will affect the subscribers.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type | Description |
|---|---|---|
T |
unknown |
Type which is pushed |
| Name | Type | Description |
|---|---|---|
path |
string |
The Path, on which the data should be changed |
content |
T |
The content to store in the given path. |
options? |
Partial<IEventAdditionalData> |
The Options, that will be forwarded to subscribers. |
void
register(emitter, options): O
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 |
I |
The Emitter to consider |
options |
IEventOptions |
O
{O}
registerSubscription<T>(path, 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 |
|---|---|---|
path |
string |
The |
subscription |
IEventCallback<T, AD> |
{INopeObserver}
IPubSubSystem.registerSubscription
toDescription(): Object
Lists all publishers and subscribers of the system.
Object
| Name | Type |
|---|---|
data |
any |
publishers |
{ name: string ; schema: INopeDescriptor }[] |
subscribers |
{ name: string ; schema: INopeDescriptor }[] |
unregister(emitter): boolean
Removes an observable of the Pub-Sub-System.
Author
M.Karkowski
Memberof
IPubSubSystem
| Name | Type |
|---|---|
emitter |
I |
boolean
{boolean}
updateMatching(): void
Helper to manually Trigger an update of the Matching. This will update subscribers and publishers and link them. Normally this is not necessary.
This will build an internal linking (based on the settings) between publishers and subscribers.
Author
M.Karkowski
Memberof
IPubSubSystem
void
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 |
I |
The Emitter to consider |
options |
IEventOptions |
The modified options |
void