@ms-cloudpack/data-bus 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,112 @@
2
2
  "name": "@ms-cloudpack/data-bus",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 09 May 2022 18:54:32 GMT",
5
+ "date": "Tue, 31 Jan 2023 08:08:54 GMT",
6
+ "tag": "@ms-cloudpack/data-bus_v0.1.1",
7
+ "version": "0.1.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "elcraig@microsoft.com",
12
+ "package": "@ms-cloudpack/data-bus",
13
+ "commit": "243bfddf2ccffa5d6aa479105156b8a5de0e66c2",
14
+ "comment": "Don't publish test files"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 23 Jan 2023 21:06:01 GMT",
21
+ "tag": "@ms-cloudpack/data-bus_v0.1.0",
22
+ "version": "0.1.0",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "elcraig@microsoft.com",
27
+ "package": "@ms-cloudpack/data-bus",
28
+ "commit": "d092bb42a995e8bab968a0fdc1f35144680b73c3",
29
+ "comment": "Move beachball disallowedChangeTypes setting to repo config"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Sat, 03 Dec 2022 08:10:45 GMT",
36
+ "tag": "@ms-cloudpack/data-bus_v0.1.0",
37
+ "version": "0.1.0",
38
+ "comments": {
39
+ "none": [
40
+ {
41
+ "author": "dake.3601@gmail.com",
42
+ "package": "@ms-cloudpack/data-bus",
43
+ "commit": "9fae6cbdb788baac8236abc9eb44eb1d3296b7e0",
44
+ "comment": "Updated beachball config to disallow major bumps"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Wed, 28 Sep 2022 08:15:16 GMT",
51
+ "tag": "@ms-cloudpack/data-bus_v0.1.0",
52
+ "version": "0.1.0",
53
+ "comments": {
54
+ "none": [
55
+ {
56
+ "author": "elcraig@microsoft.com",
57
+ "package": "@ms-cloudpack/data-bus",
58
+ "commit": "084168500b6320d6861a4c7e8f363fea9e4f831e",
59
+ "comment": "Fix lint issues with types"
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "date": "Fri, 12 Aug 2022 08:12:39 GMT",
66
+ "tag": "@ms-cloudpack/data-bus_v0.1.0",
67
+ "version": "0.1.0",
68
+ "comments": {
69
+ "minor": [
70
+ {
71
+ "author": "dzearing@microsoft.com",
72
+ "package": "@ms-cloudpack/data-bus",
73
+ "commit": "e733241cb555d1ae14cdfd8fe211d1d05b471e29",
74
+ "comment": "Providers can now be added to the root of the data tree."
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "date": "Fri, 20 May 2022 04:26:15 GMT",
81
+ "tag": "@ms-cloudpack/data-bus_v0.0.2",
82
+ "version": "0.0.2",
83
+ "comments": {
84
+ "none": [
85
+ {
86
+ "author": "dzearing@microsoft.com",
87
+ "package": "@ms-cloudpack/data-bus",
88
+ "commit": "b39bb143fc53e622c39f9e9fd349f71c9ebadd77",
89
+ "comment": "Adding api:update script."
90
+ }
91
+ ]
92
+ }
93
+ },
94
+ {
95
+ "date": "Sat, 14 May 2022 04:36:11 GMT",
96
+ "tag": "@ms-cloudpack/data-bus_v0.0.2",
97
+ "version": "0.0.2",
98
+ "comments": {
99
+ "none": [
100
+ {
101
+ "author": "dzearing@microsoft.com",
102
+ "package": "@ms-cloudpack/data-bus",
103
+ "commit": "cc0844a7d18790d69e59b16dbd6eef8fab5bc4e0",
104
+ "comment": "Updating package details."
105
+ }
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ "date": "Mon, 09 May 2022 18:54:56 GMT",
6
111
  "tag": "@ms-cloudpack/data-bus_v0.0.2",
7
112
  "version": "0.0.2",
8
113
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
1
1
  # Change Log - @ms-cloudpack/data-bus
2
2
 
3
- This log was last generated on Mon, 09 May 2022 18:54:32 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 31 Jan 2023 08:08:54 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.1.1
8
+
9
+ Tue, 31 Jan 2023 08:08:54 GMT
10
+
11
+ ### Patches
12
+
13
+ - Don't publish test files (elcraig@microsoft.com)
14
+
15
+ ## 0.1.0
16
+
17
+ Fri, 12 Aug 2022 08:12:39 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - Providers can now be added to the root of the data tree. (dzearing@microsoft.com)
22
+
7
23
  ## 0.0.2
8
24
 
9
- Mon, 09 May 2022 18:54:32 GMT
25
+ Mon, 09 May 2022 18:54:56 GMT
10
26
 
11
27
  ### Patches
12
28
 
package/README.md CHANGED
@@ -28,7 +28,7 @@ export const bus = createDataBus();
28
28
  ### Subscribing to data
29
29
 
30
30
  The data bus provides a method `subscribe` for consumers to subscribe to different types of data. As that data changes, consumers will be notified of changes. Any number of consumers can subscribe for the same data. Data is
31
- heirarchical, so you can subscribe to a full branch, or to a leaf node within the tree. Paths are represented by
31
+ hierarchical, so you can subscribe to a full branch, or to a leaf node within the tree. Paths are represented by
32
32
  string arrays.
33
33
 
34
34
  ```js
@@ -0,0 +1,5 @@
1
+ import type { DataBusState, DataBusProvider } from './types.js';
2
+ /**
3
+ * Adds a provider.
4
+ */
5
+ export declare function addProvider(state: DataBusState, provider: DataBusProvider): void;
@@ -0,0 +1,10 @@
1
+ import { getNode } from './getNode.js';
2
+ /**
3
+ * Adds a provider.
4
+ */
5
+ export function addProvider(state, provider) {
6
+ const { node } = getNode(state, provider.path, true);
7
+ node.providers ?? (node.providers = []);
8
+ node.providers.push(provider);
9
+ }
10
+ //# sourceMappingURL=addProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addProvider.js","sourceRoot":"","sources":["../src/addProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAmB,EAAE,QAAyB;IACxE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAErD,IAAI,CAAC,SAAS,KAAd,IAAI,CAAC,SAAS,GAAK,EAAE,EAAC;IACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { DataBus } from './types.js';
2
+ /**
3
+ * Creates a new data bus instance.
4
+ */
5
+ export declare function createDataBus(): DataBus;
@@ -0,0 +1,23 @@
1
+ import { addProvider } from './addProvider.js';
2
+ import { createNode } from './createNode.js';
3
+ import { getData } from './getData.js';
4
+ import { publish } from './publish.js';
5
+ import { subscribe } from './subscribe.js';
6
+ /**
7
+ * Creates a new data bus instance.
8
+ */
9
+ export function createDataBus() {
10
+ const state = {
11
+ root: createNode(),
12
+ };
13
+ const bus = {
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ publish: (path, value) => publish(state, bus, path, value),
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ getData: (path) => getData(state, path),
18
+ subscribe: (path, change) => subscribe(state, bus, path, change),
19
+ addProvider: (provider) => addProvider(state, provider),
20
+ };
21
+ return bus;
22
+ }
23
+ //# sourceMappingURL=createDataBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDataBus.js","sourceRoot":"","sources":["../src/createDataBus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,KAAK,GAAiB;QAC1B,IAAI,EAAE,UAAU,EAAE;KACnB,CAAC;IAEF,MAAM,GAAG,GAAG;QACV,8DAA8D;QAC9D,OAAO,EAAE,CAAC,IAAc,EAAE,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;QAEzE,8DAA8D;QAC9D,OAAO,EAAE,CAAc,IAAc,EAAE,EAAE,CAAC,OAAO,CAAQ,KAAK,EAAE,IAAI,CAAC;QAErE,SAAS,EAAE,CAAC,IAAc,EAAE,MAA6B,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC;QAEjG,WAAW,EAAE,CAAC,QAAyB,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;KACzE,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { DataBusNode } from './types.js';
2
+ export declare function createNode(name?: string): DataBusNode;
@@ -0,0 +1,6 @@
1
+ export function createNode(name = '') {
2
+ return {
3
+ name,
4
+ };
5
+ }
6
+ //# sourceMappingURL=createNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNode.js","sourceRoot":"","sources":["../src/createNode.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CAAC,IAAI,GAAG,EAAE;IAClC,OAAO;QACL,IAAI;KACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { DataBusState } from './types.js';
2
+ /**
3
+ * Gets data containing the corresponding props.
4
+ */
5
+ export declare function getData<TData>(state: DataBusState, path: string[]): TData | undefined;
package/lib/getData.js ADDED
@@ -0,0 +1,9 @@
1
+ import { getNode } from './getNode.js';
2
+ /**
3
+ * Gets data containing the corresponding props.
4
+ */
5
+ export function getData(state, path) {
6
+ const { node } = getNode(state, path);
7
+ return node?.value;
8
+ }
9
+ //# sourceMappingURL=getData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getData.js","sourceRoot":"","sources":["../src/getData.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,UAAU,OAAO,CAAQ,KAAmB,EAAE,IAAc;IAChE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAEtC,OAAO,IAAI,EAAE,KAA0B,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { DataBusNode, DataBusState } from './types.js';
2
+ export declare function getNode(state: DataBusState, path: string[]): {
3
+ node: DataBusNode;
4
+ nodePath: DataBusNode[];
5
+ };
6
+ export declare function getNode(state: DataBusState, path: string[], createPath: true): {
7
+ node: DataBusNode;
8
+ nodePath: DataBusNode[];
9
+ };
package/lib/getNode.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createNode } from './createNode.js';
2
+ export function getNode(state, path, createPath) {
3
+ let index = 0;
4
+ let node = state.root;
5
+ const nodePath = [state.root];
6
+ while (node && index < path.length) {
7
+ const pathName = path[index++];
8
+ if (!node.children?.[pathName] && createPath) {
9
+ node.children ?? (node.children = {});
10
+ node.children[pathName] = createNode(pathName);
11
+ }
12
+ node = node.children?.[pathName];
13
+ nodePath.push(node);
14
+ }
15
+ return {
16
+ node,
17
+ nodePath,
18
+ };
19
+ }
20
+ //# sourceMappingURL=getNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNode.js","sourceRoot":"","sources":["../src/getNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAoB7C,MAAM,UAAU,OAAO,CACrB,KAAmB,EACnB,IAAc,EACd,UAAoB;IAKpB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAA4B,KAAK,CAAC,IAAI,CAAC;IAC/C,MAAM,QAAQ,GAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE7C,OAAO,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,UAAU,EAAE;YAC5C,IAAI,CAAC,QAAQ,KAAb,IAAI,CAAC,QAAQ,GAAK,EAAE,EAAC;YACrB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;SAChD;QAED,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,IAAmB,CAAC,CAAC;KACpC;IAED,OAAO;QACL,IAAI;QACJ,QAAQ;KACT,CAAC;AACJ,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createDataBus } from './createDataBus.js';
2
+ export type { DataBus, DataBusChangeFunction, DataBusNode, DataBusProvider, DataBusState, DisposeFunction, } from './types.js';
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createDataBus } from './createDataBus.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { DataBus, DataBusState } from './types.js';
2
+ /**
3
+ * Publishes data to a given dataPath/Id.
4
+ */
5
+ export declare function publish<TData>(state: DataBusState, bus: DataBus, path: string[], value: TData): void;
package/lib/publish.js ADDED
@@ -0,0 +1,23 @@
1
+ import { getNode } from './getNode.js';
2
+ /**
3
+ * Publishes data to a given dataPath/Id.
4
+ */
5
+ export function publish(state, bus, path, value) {
6
+ const { node, nodePath } = getNode(state, path, true);
7
+ const oldValue = node.value;
8
+ // Notify pre-publishing providers and allow them to apply transforms or publish additional metadata.
9
+ for (let i = nodePath.length - 1; i >= 0; i--) {
10
+ nodePath[i].providers?.forEach((provider) => {
11
+ const newValue = provider.onPublish?.({ bus, value, oldValue, path });
12
+ if (newValue !== undefined) {
13
+ value = newValue;
14
+ }
15
+ });
16
+ }
17
+ node.value = value;
18
+ // Notify subscribers
19
+ for (let i = nodePath.length - 1; i >= 0; i--) {
20
+ nodePath[i].subscribers?.forEach((subscriber) => subscriber(value, oldValue, path));
21
+ }
22
+ }
23
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,UAAU,OAAO,CAAQ,KAAmB,EAAE,GAAY,EAAE,IAAc,EAAE,KAAY;IAC5F,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAc,CAAC;IAErC,qGAAqG;IACrG,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7C,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC1C,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAsB,CAAC;YAE3F,IAAI,QAAQ,KAAK,SAAS,EAAE;gBAC1B,KAAK,GAAG,QAAQ,CAAC;aAClB;QACH,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAEnB,qBAAqB;IACrB,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7C,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;KACrF;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { DataBusState, DataBusChangeFunction, DisposeFunction, DataBus } from './types.js';
2
+ export declare function subscribe(state: DataBusState, bus: DataBus, path: string[], change: DataBusChangeFunction): DisposeFunction;
@@ -0,0 +1,45 @@
1
+ import { getNode } from './getNode.js';
2
+ export function subscribe(state, bus, path, change) {
3
+ const { node, nodePath } = getNode(state, path, true);
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
5
+ const { value } = node;
6
+ const pathString = path.join('/');
7
+ node.subscribers ?? (node.subscribers = new Set());
8
+ node.subscribers.add(change);
9
+ // Fire the initial change with the value.
10
+ if (value !== undefined) {
11
+ change(value, value, path);
12
+ }
13
+ // Activate any deactivated providers available for this path.
14
+ for (let index = nodePath.length - 1; index >= 0; index--) {
15
+ const currentNode = nodePath[index];
16
+ if (currentNode.providers?.length) {
17
+ const activeProviders = (currentNode.activeProviders ?? (currentNode.activeProviders = {}));
18
+ currentNode.providers.forEach((provider) => {
19
+ activeProviders[pathString] ?? (activeProviders[pathString] = { provider, count: 0 });
20
+ if (activeProviders[pathString].count === 0) {
21
+ provider.onActivate?.({ path, bus });
22
+ }
23
+ activeProviders[pathString].count++;
24
+ });
25
+ }
26
+ }
27
+ return () => {
28
+ node.subscribers?.delete(change);
29
+ // Deactivate providers.
30
+ for (let index = nodePath.length - 1; index >= 0; index--) {
31
+ const currentNode = nodePath[index];
32
+ if (currentNode.providers?.length) {
33
+ const activeRecord = currentNode.activeProviders?.[pathString];
34
+ if (activeRecord) {
35
+ activeRecord.count--;
36
+ if (!activeRecord.count) {
37
+ activeRecord?.provider.onDeactivate?.({ path, bus });
38
+ delete currentNode.activeProviders?.[pathString];
39
+ }
40
+ }
41
+ }
42
+ }
43
+ };
44
+ }
45
+ //# sourceMappingURL=subscribe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../src/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,MAAM,UAAU,SAAS,CACvB,KAAmB,EACnB,GAAY,EACZ,IAAc,EACd,MAA6B;IAE7B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,mEAAmE;IACnE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IACvB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,CAAC,WAAW,KAAhB,IAAI,CAAC,WAAW,GAAK,IAAI,GAAG,EAAyB,EAAC;IACtD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE7B,0CAA0C;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;KAC5B;IAED,8DAA8D;IAC9D,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;QACzD,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEpC,IAAI,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE;YACjC,MAAM,eAAe,GAAG,CAAC,WAAW,CAAC,eAAe,KAA3B,WAAW,CAAC,eAAe,GAAK,EAAE,EAAC,CAAC;YAE7D,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACzC,eAAe,CAAC,UAAU,MAA1B,eAAe,CAAC,UAAU,IAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAC;gBAEvD,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE;oBAC3C,QAAQ,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;iBACtC;gBAED,eAAe,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,CAAC;YACtC,CAAC,CAAC,CAAC;SACJ;KACF;IAED,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAEjC,wBAAwB;QACxB,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;YACzD,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEpC,IAAI,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE;gBACjC,MAAM,YAAY,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,CAAC;gBAE/D,IAAI,YAAY,EAAE;oBAChB,YAAY,CAAC,KAAK,EAAE,CAAC;oBAErB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;wBACvB,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;wBACrD,OAAO,WAAW,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,CAAC;qBAClD;iBACF;aACF;SACF;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.0"
9
+ }
10
+ ]
11
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ export type DataBusChangeFunction = <TData>(value: TData, oldValue: TData, path: string[]) => void;
2
+ export type DisposeFunction = () => void;
3
+ export interface DataBusProvider<TData = any> {
4
+ path: string[];
5
+ onActivate?: (options: {
6
+ path: string[];
7
+ bus: DataBus;
8
+ }) => void;
9
+ onDeactivate?: (options: {
10
+ path: string[];
11
+ bus: DataBus;
12
+ }) => void;
13
+ onPublish?: (options: {
14
+ value: TData;
15
+ oldValue: TData;
16
+ path: string[];
17
+ bus: DataBus;
18
+ }) => TData | undefined;
19
+ }
20
+ export interface DataBusNode {
21
+ name?: string;
22
+ value?: any;
23
+ providers?: DataBusProvider[];
24
+ activeProviders?: Record<string, {
25
+ provider: DataBusProvider;
26
+ count: number;
27
+ }>;
28
+ subscribers?: Set<DataBusChangeFunction>;
29
+ children?: Record<string, DataBusNode>;
30
+ }
31
+ export interface DataBusState {
32
+ root: DataBusNode;
33
+ }
34
+ export interface DataBus {
35
+ publish: (path: string[], value: any) => void;
36
+ subscribe: (path: string[], callback: DataBusChangeFunction) => DisposeFunction;
37
+ getData: (path: string[]) => any;
38
+ addProvider: (provider: DataBusProvider) => void;
39
+ }
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/data-bus",
3
- "version": "0.0.2",
4
- "description": "",
3
+ "version": "0.1.1",
4
+ "description": "A data bus implementation.",
5
+ "license": "MIT",
5
6
  "type": "module",
6
7
  "types": "./lib/index.js",
7
8
  "sideEffects": false,
@@ -12,18 +13,21 @@
12
13
  }
13
14
  },
14
15
  "scripts": {
15
- "build": "just-scripts build",
16
- "build:watch": "just-scripts build:watch",
17
- "lint": "just-scripts lint",
18
- "lint:fix": "just-scripts lint:fix",
19
- "test": "just-scripts test",
20
- "test:watch": "just-scripts test:watch"
16
+ "api:update": "cloudpack-scripts api-update",
17
+ "api": "cloudpack-scripts api",
18
+ "build:watch": "cloudpack-scripts build-watch",
19
+ "build": "cloudpack-scripts build",
20
+ "lint:update": "cloudpack-scripts lint-update",
21
+ "lint": "cloudpack-scripts lint",
22
+ "test:update": "cloudpack-scripts test-update",
23
+ "test:watch": "cloudpack-scripts test-watch",
24
+ "test": "cloudpack-scripts test"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@ms-cloudpack/scripts": "*",
24
28
  "@ms-cloudpack/eslint-config-base": "*"
25
29
  },
26
30
  "files": [
27
- "/lib"
31
+ "lib/**/!(*.test.*)"
28
32
  ]
29
33
  }