@ms-cloudpack/data-bus 0.3.0 → 0.3.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/lib/addProvider.js +1 -1
- package/lib/addProvider.js.map +1 -1
- package/lib/getNode.js +2 -2
- package/lib/getNode.js.map +1 -1
- package/lib/subscribe.js +3 -3
- package/lib/subscribe.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +1 -1
package/lib/addProvider.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getNode } from './getNode.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export function addProvider(state, provider) {
|
|
6
6
|
const { node } = getNode(state, provider.path, true);
|
|
7
|
-
node.providers
|
|
7
|
+
node.providers ??= [];
|
|
8
8
|
node.providers.push(provider);
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=addProvider.js.map
|
package/lib/addProvider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addProvider.js","sourceRoot":"","sources":["../src/addProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC;;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,
|
|
1
|
+
{"version":3,"file":"addProvider.js","sourceRoot":"","sources":["../src/addProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC;;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,KAAK,EAAE,CAAC;IACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { getNode } from './getNode.js';\nimport type { DataBusProvider } from './types/DataBusProvider.js';\nimport type { DataBusState } from './types/DataBusState.js';\n\n/**\n * Adds a provider.\n */\nexport function addProvider(state: DataBusState, provider: DataBusProvider) {\n const { node } = getNode(state, provider.path, true);\n\n node.providers ??= [];\n node.providers.push(provider);\n}\n"]}
|
package/lib/getNode.js
CHANGED
|
@@ -6,11 +6,11 @@ export function getNode(state, path, createPath) {
|
|
|
6
6
|
while (node && index < path.length) {
|
|
7
7
|
const pathName = path[index++];
|
|
8
8
|
if (!node.children?.[pathName] && createPath) {
|
|
9
|
-
node.children
|
|
9
|
+
node.children ??= {};
|
|
10
10
|
node.children[pathName] = createNode(pathName);
|
|
11
11
|
}
|
|
12
12
|
node = node.children?.[pathName];
|
|
13
|
-
nodePath.push(node);
|
|
13
|
+
node && nodePath.push(node);
|
|
14
14
|
}
|
|
15
15
|
return {
|
|
16
16
|
node,
|
package/lib/getNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNode.js","sourceRoot":"","sources":["../src/getNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAqB7C,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,
|
|
1
|
+
{"version":3,"file":"getNode.js","sourceRoot":"","sources":["../src/getNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAqB7C,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,KAAK,EAAE,CAAC;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,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC7B;IAED,OAAO;QACL,IAAI;QACJ,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["import { createNode } from './createNode.js';\nimport type { DataBusNode } from './types/DataBusNode.js';\nimport type { DataBusState } from './types/DataBusState.js';\n\nexport function getNode(\n state: DataBusState,\n path: string[],\n): {\n node: DataBusNode;\n nodePath: DataBusNode[];\n};\n\nexport function getNode(\n state: DataBusState,\n path: string[],\n createPath: true,\n): {\n node: DataBusNode;\n nodePath: DataBusNode[];\n};\n\nexport function getNode(\n state: DataBusState,\n path: string[],\n createPath?: boolean,\n): {\n node: DataBusNode | undefined;\n nodePath: DataBusNode[];\n} {\n let index = 0;\n let node: DataBusNode | undefined = state.root;\n const nodePath: DataBusNode[] = [state.root];\n\n while (node && index < path.length) {\n const pathName = path[index++];\n\n if (!node.children?.[pathName] && createPath) {\n node.children ??= {};\n node.children[pathName] = createNode(pathName);\n }\n\n node = node.children?.[pathName];\n node && nodePath.push(node);\n }\n\n return {\n node,\n nodePath,\n };\n}\n"]}
|
package/lib/subscribe.js
CHANGED
|
@@ -4,7 +4,7 @@ export function subscribe(state, bus, path, change) {
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
5
5
|
const { value } = node;
|
|
6
6
|
const pathString = path.join('/');
|
|
7
|
-
node.subscribers
|
|
7
|
+
node.subscribers ??= new Set();
|
|
8
8
|
node.subscribers.add(change);
|
|
9
9
|
// Fire the initial change with the value.
|
|
10
10
|
if (value !== undefined) {
|
|
@@ -14,9 +14,9 @@ export function subscribe(state, bus, path, change) {
|
|
|
14
14
|
for (let index = nodePath.length - 1; index >= 0; index--) {
|
|
15
15
|
const currentNode = nodePath[index];
|
|
16
16
|
if (currentNode.providers?.length) {
|
|
17
|
-
const activeProviders = (currentNode.activeProviders
|
|
17
|
+
const activeProviders = (currentNode.activeProviders ??= {});
|
|
18
18
|
currentNode.providers.forEach((provider) => {
|
|
19
|
-
activeProviders[pathString]
|
|
19
|
+
activeProviders[pathString] ??= { provider, count: 0 };
|
|
20
20
|
if (activeProviders[pathString].count === 0) {
|
|
21
21
|
provider.onActivate?.({ path, bus });
|
|
22
22
|
}
|
package/lib/subscribe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../src/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAMvC,MAAM,UAAU,SAAS,CACvB,KAAmB,EACnB,GAAY,EACZ,IAAc,EACd,MAA6B;IAE7B,MAAM,EAAE,IAAI,EA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AAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACzC,eAAe,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;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","sourcesContent":["import { getNode } from './getNode.js';\nimport type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';\nimport type { DisposeFunction } from './types/DisposeFunction.js';\nimport type { DataBusState } from './types/DataBusState.js';\nimport type { DataBus } from './types/DataBus.js';\n\nexport function subscribe(\n state: DataBusState,\n bus: DataBus,\n path: string[],\n change: DataBusChangeFunction,\n): DisposeFunction {\n const { node, nodePath } = getNode(state, path, true);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const { value } = node;\n const pathString = path.join('/');\n\n node.subscribers ??= new Set<DataBusChangeFunction>();\n node.subscribers.add(change);\n\n // Fire the initial change with the value.\n if (value !== undefined) {\n change(value, value, path);\n }\n\n // Activate any deactivated providers available for this path.\n for (let index = nodePath.length - 1; index >= 0; index--) {\n const currentNode = nodePath[index];\n\n if (currentNode.providers?.length) {\n const activeProviders = (currentNode.activeProviders ??= {});\n\n currentNode.providers.forEach((provider) => {\n activeProviders[pathString] ??= { provider, count: 0 };\n\n if (activeProviders[pathString].count === 0) {\n provider.onActivate?.({ path, bus });\n }\n\n activeProviders[pathString].count++;\n });\n }\n }\n\n return () => {\n node.subscribers?.delete(change);\n\n // Deactivate providers.\n for (let index = nodePath.length - 1; index >= 0; index--) {\n const currentNode = nodePath[index];\n\n if (currentNode.providers?.length) {\n const activeRecord = currentNode.activeProviders?.[pathString];\n\n if (activeRecord) {\n activeRecord.count--;\n\n if (!activeRecord.count) {\n activeRecord?.provider.onDeactivate?.({ path, bus });\n delete currentNode.activeProviders?.[pathString];\n }\n }\n }\n }\n };\n}\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED