j-templates 7.0.64 → 7.0.66

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/DOM/elements.d.ts CHANGED
@@ -86,6 +86,22 @@ export declare const table: <T>(config: {
86
86
  on?: import("../Node/vNode.types").FunctionOr<import("../Node/vNode.types").vNodeEvents<HTMLElementEventMap>>;
87
87
  data?: () => T | Array<T> | Promise<Array<T>> | Promise<T>;
88
88
  }, children?: import("../Node/vNode.types").vNode[] | import("../Node/vNode.types").vNodeChildrenFunction<T>) => import("../Node/vNode.types").vNode;
89
+ export declare const thead: <T>(config: {
90
+ props?: import("../Node/vNode.types").FunctionOr<import("../Utils/utils.types").RecursivePartial<HTMLElement>>;
91
+ attrs?: import("../Node/vNode.types").FunctionOr<{
92
+ [name: string]: string;
93
+ }>;
94
+ on?: import("../Node/vNode.types").FunctionOr<import("../Node/vNode.types").vNodeEvents<HTMLElementEventMap>>;
95
+ data?: () => T | Array<T> | Promise<Array<T>> | Promise<T>;
96
+ }, children?: import("../Node/vNode.types").vNode[] | import("../Node/vNode.types").vNodeChildrenFunction<T>) => import("../Node/vNode.types").vNode;
97
+ export declare const th: <T>(config: {
98
+ props?: import("../Node/vNode.types").FunctionOr<import("../Utils/utils.types").RecursivePartial<HTMLElement>>;
99
+ attrs?: import("../Node/vNode.types").FunctionOr<{
100
+ [name: string]: string;
101
+ }>;
102
+ on?: import("../Node/vNode.types").FunctionOr<import("../Node/vNode.types").vNodeEvents<HTMLElementEventMap>>;
103
+ data?: () => T | Array<T> | Promise<Array<T>> | Promise<T>;
104
+ }, children?: import("../Node/vNode.types").vNode[] | import("../Node/vNode.types").vNodeChildrenFunction<T>) => import("../Node/vNode.types").vNode;
89
105
  export declare const tbody: <T>(config: {
90
106
  props?: import("../Node/vNode.types").FunctionOr<import("../Utils/utils.types").RecursivePartial<HTMLElement>>;
91
107
  attrs?: import("../Node/vNode.types").FunctionOr<{
package/DOM/elements.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.text = exports.pre = exports.label = exports.p = exports.aside = exports.option = exports.select = exports.video = exports.img = exports.td = exports.tr = exports.tbody = exports.table = exports.span = exports.textarea = exports.input = exports.h3 = exports.h2 = exports.h1 = exports.button = exports.b = exports.a = exports.div = void 0;
3
+ exports.text = exports.pre = exports.label = exports.p = exports.aside = exports.option = exports.select = exports.video = exports.img = exports.td = exports.tr = exports.tbody = exports.th = exports.thead = exports.table = exports.span = exports.textarea = exports.input = exports.h3 = exports.h2 = exports.h1 = exports.button = exports.b = exports.a = exports.div = void 0;
4
4
  const vNode_1 = require("../Node/vNode");
5
5
  exports.div = vNode_1.vNode.ToFunction("div");
6
6
  exports.a = vNode_1.vNode.ToFunction("a");
@@ -13,6 +13,8 @@ exports.input = vNode_1.vNode.ToFunction("input");
13
13
  exports.textarea = vNode_1.vNode.ToFunction("textarea");
14
14
  exports.span = vNode_1.vNode.ToFunction("span");
15
15
  exports.table = vNode_1.vNode.ToFunction("table");
16
+ exports.thead = vNode_1.vNode.ToFunction("thead");
17
+ exports.th = vNode_1.vNode.ToFunction("th");
16
18
  exports.tbody = vNode_1.vNode.ToFunction("tbody");
17
19
  exports.tr = vNode_1.vNode.ToFunction("tr");
18
20
  exports.td = vNode_1.vNode.ToFunction("td");
package/DOM/index.js CHANGED
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./elements"), exports);
18
+ // export * from "./svgElements";
18
19
  __exportStar(require("./createPropertyAssignment"), exports);
19
20
  __exportStar(require("./createEventAssignment"), exports);
@@ -0,0 +1,12 @@
1
+ // import { ElementNode } from "../Node/elementNode";
2
+ // import { ElementChildrenFunction, ElementNodeFunctionParam } from "../Node/elementNode.types";
3
+ // const svgNs = "http://www.w3.org/2000/svg";
4
+ // export function svg<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunction<T>) {
5
+ // return ElementNode.Create("svg", svgNs, nodeDef, children);
6
+ // }
7
+ // export function g<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunction<T>) {
8
+ // return ElementNode.Create("g", svgNs, nodeDef, children);
9
+ // }
10
+ // export function circle<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunction<T>) {
11
+ // return ElementNode.Create("circle", svgNs, nodeDef, children);
12
+ // }
@@ -2,21 +2,73 @@ import { ComponentEvents } from "./component.types";
2
2
  import { ObservableScope } from "../Store/Tree/observableScope";
3
3
  import { FunctionOr, vNode as vNodeType } from "./vNode.types";
4
4
  import { RecursivePartial } from "../Utils/utils.types";
5
+ /**
6
+ * Base Component class.
7
+ *
8
+ * @template D - Data type for the component's scoped state.
9
+ * @template T - Template type used by the component.
10
+ * @template E - Event map type for component events.
11
+ */
5
12
  export declare class Component<D = void, T = void, E = {}> {
6
13
  private vNode;
7
- private componentEvents;
8
14
  private scope;
9
15
  private templates;
16
+ private componentEvents;
17
+ /**
18
+ * Returns the component's virtual node injector.
19
+ */
10
20
  get Injector(): import("../Utils/injector").Injector;
21
+ /**
22
+ * Indicates whether the component has been destroyed.
23
+ */
11
24
  get Destroyed(): boolean;
25
+ /**
26
+ * Internal scoped Observable for component state.
27
+ */
12
28
  protected get Scope(): ObservableScope<D>;
29
+ /**
30
+ * Current data value from the scoped Observable.
31
+ */
13
32
  protected get Data(): D;
33
+ /**
34
+ * Accessor for the component's virtual node.
35
+ */
14
36
  protected get VNode(): vNodeType;
37
+ /**
38
+ * Accessor for the component's template collection.
39
+ */
15
40
  protected get Templates(): T;
16
- constructor(data: D | (() => D | Promise<D>), templates: T, vNode: vNodeType, componentEvents: ComponentEvents<E>);
41
+ /**
42
+ * Creates a new Component instance. Not intended to be overriden.
43
+ *
44
+ * @param data - Initial data or a factory function returning data/promise.
45
+ * @param templates - Template definitions for rendering.
46
+ * @param vNode - The underlying virtual node instance.
47
+ * @param componentEvents - Optional event callbacks.
48
+ */
49
+ constructor(vNode: vNodeType, config: vComponentConfig<D, E>, templates: T);
50
+ /**
51
+ * Returns the component's rendered vNode(s).
52
+ * Override to provide custom rendering logic.
53
+ *
54
+ * @returns A vNode or array of vNodes representing the component UI.
55
+ */
17
56
  Template(): vNodeType | vNodeType[];
57
+ /**
58
+ * Lifecycle hook called after the component has been bound to the DOM.
59
+ * Override to perform post‑binding initialization.
60
+ */
18
61
  Bound(): void;
62
+ /**
63
+ * Fires a component event.
64
+ *
65
+ * @param event - The event name to fire.
66
+ * @param data - Optional payload for the event.
67
+ */
19
68
  Fire<P extends keyof E>(event: P, data?: E[P]): void;
69
+ /**
70
+ * Destroys the component, cleaning up its scoped data and decorators.
71
+ */
20
72
  Destroy(): void;
21
73
  }
22
74
  type vComponentConfig<D, E, P = HTMLElement> = {
@@ -24,12 +76,23 @@ type vComponentConfig<D, E, P = HTMLElement> = {
24
76
  props?: FunctionOr<RecursivePartial<P>> | undefined;
25
77
  on?: ComponentEvents<E> | undefined;
26
78
  };
27
- type ComponentConstructor<D, T, E> = {
28
- new (data: D | (() => D | Promise<D>), templates: T, vNode: vNodeType, componentEvents: ComponentEvents<E>): Component<D, T, E>;
29
- };
30
79
  export declare namespace Component {
31
- function ToFunction<D, T, E, P = HTMLElement>(type: string, constructor: ComponentConstructor<D, T, E>, namespace?: string): (config: vComponentConfig<D, E, P>, templates?: T) => vNodeType;
32
- function Register<D = void, T = void, E = void>(name: string, constructor: ComponentConstructor<D, T, E>): void;
80
+ /**
81
+ * Function wraps the Component as a function that can be used to create vNode objects
82
+ * and generate templates.
83
+ */
84
+ function ToFunction<D, T, E, P = HTMLElement>(type: string, constructor: typeof Component<D, T, E>, namespace?: string): (config: vComponentConfig<D, E, P>, templates?: T) => vNodeType;
85
+ /**
86
+ * Function registers the Component as a WebComponent as the provided name.
87
+ */
88
+ function Register<D = void, T = void, E = void>(name: string, constructor: typeof Component<D, T, E>): void;
89
+ /**
90
+ * Attaches a virtual node to a real DOM node.
91
+ *
92
+ * @param node - The target DOM node to attach to.
93
+ * @param vnode - The virtual node to be attached.
94
+ * @returns The result of the attachment operation.
95
+ */
33
96
  function Attach(node: any, vnode: vNodeType): vNodeType;
34
97
  }
35
98
  export {};
package/Node/component.js CHANGED
@@ -4,67 +4,156 @@ exports.Component = void 0;
4
4
  const decorators_1 = require("../Utils/decorators");
5
5
  const observableScope_1 = require("../Store/Tree/observableScope");
6
6
  const vNode_1 = require("./vNode");
7
+ /**
8
+ * Base Component class.
9
+ *
10
+ * @template D - Data type for the component's scoped state.
11
+ * @template T - Template type used by the component.
12
+ * @template E - Event map type for component events.
13
+ */
7
14
  class Component {
15
+ /**
16
+ * Returns the component's virtual node injector.
17
+ */
8
18
  get Injector() {
9
19
  return this.vNode.injector;
10
20
  }
21
+ /**
22
+ * Indicates whether the component has been destroyed.
23
+ */
11
24
  get Destroyed() {
12
25
  return this.vNode.destroyed;
13
26
  }
27
+ /**
28
+ * Internal scoped Observable for component state.
29
+ */
14
30
  get Scope() {
15
31
  return this.scope;
16
32
  }
33
+ /**
34
+ * Current data value from the scoped Observable.
35
+ */
17
36
  get Data() {
18
37
  return this.scope.Value;
19
38
  }
39
+ /**
40
+ * Accessor for the component's virtual node.
41
+ */
20
42
  get VNode() {
21
43
  return this.vNode;
22
44
  }
45
+ /**
46
+ * Accessor for the component's template collection.
47
+ */
23
48
  get Templates() {
24
49
  return this.templates;
25
50
  }
26
- constructor(data, templates, vNode, componentEvents) {
51
+ /**
52
+ * Creates a new Component instance. Not intended to be overriden.
53
+ *
54
+ * @param data - Initial data or a factory function returning data/promise.
55
+ * @param templates - Template definitions for rendering.
56
+ * @param vNode - The underlying virtual node instance.
57
+ * @param componentEvents - Optional event callbacks.
58
+ */
59
+ /* constructor(
60
+ data: D | (() => D | Promise<D>),
61
+ templates: T,
62
+ private vNode: vNodeType,
63
+ private componentEvents: ComponentEvents<E>,
64
+ ) {
65
+ if (typeof data === "function")
66
+ this.scope = new ObservableScope<D>(data as () => D | Promise<D>);
67
+ else this.scope = new ObservableScope<D>(() => data);
68
+
69
+ this.templates = templates || ({} as T);
70
+ } */
71
+ constructor(vNode, config, templates) {
27
72
  this.vNode = vNode;
28
- this.componentEvents = componentEvents;
73
+ const { data, on } = config;
29
74
  if (typeof data === "function")
30
75
  this.scope = new observableScope_1.ObservableScope(data);
31
76
  else
32
77
  this.scope = new observableScope_1.ObservableScope(() => data);
78
+ this.componentEvents = on;
33
79
  this.templates = templates || {};
34
80
  }
81
+ /**
82
+ * Returns the component's rendered vNode(s).
83
+ * Override to provide custom rendering logic.
84
+ *
85
+ * @returns A vNode or array of vNodes representing the component UI.
86
+ */
35
87
  Template() {
36
88
  return [];
37
89
  }
38
- Bound() { }
90
+ /**
91
+ * Lifecycle hook called after the component has been bound to the DOM.
92
+ * Override to perform post‑binding initialization.
93
+ */
94
+ Bound() {
95
+ decorators_1.Bound.All(this);
96
+ }
97
+ /**
98
+ * Fires a component event.
99
+ *
100
+ * @param event - The event name to fire.
101
+ * @param data - Optional payload for the event.
102
+ */
39
103
  Fire(event, data) {
40
104
  var eventCallback = this.componentEvents && this.componentEvents[event];
41
105
  eventCallback && eventCallback(data);
42
106
  }
107
+ /**
108
+ * Destroys the component, cleaning up its scoped data and decorators.
109
+ */
43
110
  Destroy() {
44
111
  this.scope.Destroy();
45
112
  decorators_1.Destroy.All(this);
46
113
  }
47
114
  }
48
115
  exports.Component = Component;
116
+ /* type ComponentConstructor<D, T, E> = {
117
+ new (
118
+ data: D | (() => D | Promise<D>),
119
+ templates: T,
120
+ vNode: vNodeType,
121
+ componentEvents: ComponentEvents<E>,
122
+ ): Component<D, T, E>;
123
+ }; */
49
124
  (function (Component) {
50
- function ToFunction(type, constructor, namespace) {
125
+ /**
126
+ * Function wraps the Component as a function that can be used to create vNode objects
127
+ * and generate templates.
128
+ */
129
+ function ToFunction(type,
130
+ // constructor: ComponentConstructor<D, T, E>,
131
+ constructor, namespace) {
51
132
  return function (config, templates) {
52
- const { data, on, props } = config;
133
+ /* const { data, on, props } = config;
134
+
53
135
  class ConcreteComponent extends constructor {
54
- constructor(vnode) {
55
- super(data, templates, vnode, on);
56
- }
136
+ constructor(vnode: vNodeType) {
137
+ super(data, templates, vnode, on);
138
+ }
139
+ } */
140
+ function ComponentFactory(vnode) {
141
+ return new constructor(vnode, config, templates);
57
142
  }
58
143
  const definition = {
59
144
  type,
60
145
  namespace: namespace ?? null,
61
- props,
62
- componentConstructor: ConcreteComponent,
146
+ props: config.props,
147
+ componentFactory: ComponentFactory,
148
+ // componentConstructor: ConcreteComponent,
63
149
  };
64
150
  return vNode_1.vNode.Create(definition);
65
151
  };
66
152
  }
67
153
  Component.ToFunction = ToFunction;
154
+ /**
155
+ * Function registers the Component as a WebComponent as the provided name.
156
+ */
68
157
  function Register(name, constructor) {
69
158
  const componentFunction = ToFunction(`${name}-component`, constructor);
70
159
  class WebComponent extends HTMLElement {
@@ -78,6 +167,13 @@ exports.Component = Component;
78
167
  customElements.define(name, WebComponent);
79
168
  }
80
169
  Component.Register = Register;
170
+ /**
171
+ * Attaches a virtual node to a real DOM node.
172
+ *
173
+ * @param node - The target DOM node to attach to.
174
+ * @param vnode - The virtual node to be attached.
175
+ * @returns The result of the attachment operation.
176
+ */
81
177
  function Attach(node, vnode) {
82
178
  return vNode_1.vNode.Attach(node, vnode);
83
179
  }
package/Node/vNode.js CHANGED
@@ -14,7 +14,8 @@ var vNode;
14
14
  return {
15
15
  definition,
16
16
  type: definition.type,
17
- injector: definition.componentConstructor
17
+ // injector: definition.componentConstructor
18
+ injector: definition.componentFactory
18
19
  ? injector_1.Injector.Scope(injector_1.Injector.Current(), function () {
19
20
  return new injector_1.Injector();
20
21
  })
@@ -94,7 +95,9 @@ var vNode;
94
95
  vNode.Attach = Attach;
95
96
  })(vNode || (exports.vNode = vNode = {}));
96
97
  function InitNode(vnode) {
97
- const { type, namespace, props, attrs, on, data, componentConstructor, children, childrenArray, } = vnode.definition;
98
+ const { type, namespace, props, attrs, on, data,
99
+ // componentConstructor,
100
+ componentFactory, children, childrenArray, } = vnode.definition;
98
101
  const node = (vnode.node =
99
102
  vnode.definition.node ?? nodeConfig_1.NodeConfig.createNode(type, namespace));
100
103
  vnode.definition = null;
@@ -137,8 +140,10 @@ function InitNode(vnode) {
137
140
  else
138
141
  assignAttributes(attrs);
139
142
  }
140
- if (componentConstructor) {
141
- vnode.component = new componentConstructor(vnode);
143
+ // if (componentConstructor) {
144
+ if (componentFactory) {
145
+ // vnode.component = new componentConstructor(vnode);
146
+ vnode.component = componentFactory(vnode);
142
147
  vnode.component.Bound();
143
148
  function componentChildren() {
144
149
  return vnode.component.Template();
@@ -163,6 +168,7 @@ function Children(vnode, children, data) {
163
168
  return;
164
169
  const startChildren = vnode.children;
165
170
  const newChildren = Store_1.ObservableScope.Value(scope);
171
+ // AssignChildren(vnode, scope);
166
172
  if (startChildren !== newChildren) {
167
173
  vnode.children = newChildren;
168
174
  UpdateChildren(vnode);
@@ -170,11 +176,21 @@ function Children(vnode, children, data) {
170
176
  }));
171
177
  }
172
178
  vnode.children = childNodes;
179
+ // AssignChildren(vnode, childrenScope);
173
180
  }
174
- function AssignChildren(vnode, childrenScope) {
175
- const children = Store_1.ObservableScope.Peek(childrenScope);
176
- vnode.children = children;
177
- }
181
+ /* function AssignChildren(
182
+ vnode: vNodeType,
183
+ childrenScope: IObservableScope<
184
+ [
185
+ any,
186
+ vNodeType[],
187
+ IObservableScope<string | vNodeType | vNodeType[]> | null,
188
+ ][]
189
+ >,
190
+ ) {
191
+ const children = ObservableScope.Peek(childrenScope);
192
+ vnode.children = children;
193
+ } */
178
194
  const DEFAULT_DATA = [undefined];
179
195
  function DefaultData() {
180
196
  return DEFAULT_DATA;
@@ -37,7 +37,5 @@ export type vNodeDefinition<P = HTMLElement, E = HTMLElementEventMap, T = never>
37
37
  data?: () => T | Array<T> | Promise<Array<T>> | Promise<T>;
38
38
  children?: vNodeChildrenFunction<T>;
39
39
  childrenArray?: vNode[];
40
- componentConstructor?: {
41
- new (vnode: vNode): Component<any, any, any>;
42
- };
40
+ componentFactory?: (vnode: vNode) => Component<any, any, any>;
43
41
  };
@@ -1,11 +1,89 @@
1
1
  import { Store } from "./store";
2
+ /**
3
+ * StoreAsync class extends the base Store class to provide asynchronous data management operations.
4
+ * This class handles writing, patching, pushing, and splicing data in an asynchronous manner.
5
+ *
6
+ * StoreAsync is designed to work with observable data structures, allowing for efficient updates
7
+ * and notifications when data changes. It is particularly useful for scenarios where asynchronous
8
+ * operations are preferred or required, such as handling large datasets or performing complex diffs
9
+ * without blocking the main thread.
10
+ *
11
+ * @example
12
+ * // Creating a StoreAsync instance
13
+ * const store = new StoreAsync();
14
+ *
15
+ * // Writing data to the store asynchronously
16
+ * await store.Write({ name: "John", age: 30 }, "user");
17
+ *
18
+ * // Patching existing data asynchronously
19
+ * await store.Patch("user", { age: 31 });
20
+ *
21
+ * // Pushing data into an array asynchronously
22
+ * await store.Push("user.array", { id: 1 }, { id: 2 });
23
+ *
24
+ * // Splicing an array asynchronously
25
+ * const deletedItems = await store.Splice("user.array", 0, 1, { id: 3 });
26
+ *
27
+ * // Cleaning up resources
28
+ * store.Destroy();
29
+ *
30
+ * @see Store
31
+ * @see StoreSync
32
+ * @see DiffAsync
33
+ */
2
34
  export declare class StoreAsync extends Store {
35
+ /**
36
+ * The diff instance used to compute differences between current and new data states asynchronously.
37
+ * @private
38
+ */
3
39
  private diff;
40
+ /**
41
+ * The async queue instance used to manage asynchronous operations in a non-blocking manner.
42
+ * @private
43
+ */
4
44
  private queue;
45
+ /**
46
+ * Creates an instance of StoreAsync.
47
+ * @param keyFunc Optional function to generate a key for a given data value.
48
+ */
5
49
  constructor(keyFunc?: (value: any) => string | undefined);
50
+ /**
51
+ * Writes data to the store asynchronously.
52
+ * This method ensures that write operations are queued and executed in a non-blocking manner.
53
+ * @param data The data to be written. Can be of any type.
54
+ * @param key Optional key for the data. If not provided, the keyFunc will be used to generate a key.
55
+ * @throws Will throw an error if no key is provided for the data.
56
+ */
6
57
  Write(data: unknown, key?: string): Promise<void>;
58
+ /**
59
+ * Patches an existing value in the store with new data asynchronously.
60
+ * This method ensures that patch operations are queued and executed in a non-blocking manner.
61
+ * @param key The key of the value to be patched.
62
+ * @param patch The patch data to be merged with the existing value.
63
+ * @throws Will throw an error if the value to be patched is undefined.
64
+ */
7
65
  Patch(key: string, patch: unknown): Promise<void>;
66
+ /**
67
+ * Pushes data into an array stored at the specified key asynchronously.
68
+ * This method ensures that push operations are queued and executed in a non-blocking manner.
69
+ * @param key The key of the array where data will be pushed.
70
+ * @param data The data items to be pushed into the array.
71
+ */
8
72
  Push(key: string, ...data: unknown[]): Promise<void>;
73
+ /**
74
+ * Splices an array stored at the specified key with new data asynchronously.
75
+ * This method ensures that splice operations are queued and executed in a non-blocking manner.
76
+ * It modifies the array by deleting elements and inserting new ones at the specified position.
77
+ * @param key The key of the array to be spliced.
78
+ * @param start The position at which to start changing the array.
79
+ * @param deleteCount Optional number of elements to delete. If not provided, all elements from start to end will be deleted.
80
+ * @param items Optional elements to insert into the array.
81
+ * @returns The array of deleted elements.
82
+ */
9
83
  Splice(key: string, start: number, deleteCount?: number, ...items: unknown[]): Promise<any[]>;
84
+ /**
85
+ * Destroys the StoreAsync instance, stopping the async queue and cleaning up the diff instance.
86
+ * This method should be called when the instance is no longer needed to free up resources.
87
+ */
10
88
  Destroy(): void;
11
89
  }
@@ -6,12 +6,59 @@ const json_1 = require("../../Utils/json");
6
6
  const diffAsync_1 = require("../Diff/diffAsync");
7
7
  const observableNode_1 = require("../Tree/observableNode");
8
8
  const store_1 = require("./store");
9
+ /**
10
+ * StoreAsync class extends the base Store class to provide asynchronous data management operations.
11
+ * This class handles writing, patching, pushing, and splicing data in an asynchronous manner.
12
+ *
13
+ * StoreAsync is designed to work with observable data structures, allowing for efficient updates
14
+ * and notifications when data changes. It is particularly useful for scenarios where asynchronous
15
+ * operations are preferred or required, such as handling large datasets or performing complex diffs
16
+ * without blocking the main thread.
17
+ *
18
+ * @example
19
+ * // Creating a StoreAsync instance
20
+ * const store = new StoreAsync();
21
+ *
22
+ * // Writing data to the store asynchronously
23
+ * await store.Write({ name: "John", age: 30 }, "user");
24
+ *
25
+ * // Patching existing data asynchronously
26
+ * await store.Patch("user", { age: 31 });
27
+ *
28
+ * // Pushing data into an array asynchronously
29
+ * await store.Push("user.array", { id: 1 }, { id: 2 });
30
+ *
31
+ * // Splicing an array asynchronously
32
+ * const deletedItems = await store.Splice("user.array", 0, 1, { id: 3 });
33
+ *
34
+ * // Cleaning up resources
35
+ * store.Destroy();
36
+ *
37
+ * @see Store
38
+ * @see StoreSync
39
+ * @see DiffAsync
40
+ */
9
41
  class StoreAsync extends store_1.Store {
42
+ /**
43
+ * Creates an instance of StoreAsync.
44
+ * @param keyFunc Optional function to generate a key for a given data value.
45
+ */
10
46
  constructor(keyFunc) {
11
47
  super(keyFunc);
48
+ /**
49
+ * The async queue instance used to manage asynchronous operations in a non-blocking manner.
50
+ * @private
51
+ */
12
52
  this.queue = new asyncQueue_1.AsyncQueue();
13
53
  this.diff = new diffAsync_1.DiffAsync(keyFunc);
14
54
  }
55
+ /**
56
+ * Writes data to the store asynchronously.
57
+ * This method ensures that write operations are queued and executed in a non-blocking manner.
58
+ * @param data The data to be written. Can be of any type.
59
+ * @param key Optional key for the data. If not provided, the keyFunc will be used to generate a key.
60
+ * @throws Will throw an error if no key is provided for the data.
61
+ */
15
62
  async Write(data, key) {
16
63
  await this.queue.Next(async () => {
17
64
  key = key || this.keyFunc?.(data);
@@ -21,6 +68,13 @@ class StoreAsync extends store_1.Store {
21
68
  this.UpdateRootMap(diffResult);
22
69
  });
23
70
  }
71
+ /**
72
+ * Patches an existing value in the store with new data asynchronously.
73
+ * This method ensures that patch operations are queued and executed in a non-blocking manner.
74
+ * @param key The key of the value to be patched.
75
+ * @param patch The patch data to be merged with the existing value.
76
+ * @throws Will throw an error if the value to be patched is undefined.
77
+ */
24
78
  async Patch(key, patch) {
25
79
  await this.queue.Next(async () => {
26
80
  const value = this.Get(key);
@@ -32,6 +86,12 @@ class StoreAsync extends store_1.Store {
32
86
  this.UpdateRootMap(diffResult);
33
87
  });
34
88
  }
89
+ /**
90
+ * Pushes data into an array stored at the specified key asynchronously.
91
+ * This method ensures that push operations are queued and executed in a non-blocking manner.
92
+ * @param key The key of the array where data will be pushed.
93
+ * @param data The data items to be pushed into the array.
94
+ */
35
95
  async Push(key, ...data) {
36
96
  await this.queue.Next(async () => {
37
97
  const arr = this.Get(key);
@@ -45,6 +105,16 @@ class StoreAsync extends store_1.Store {
45
105
  this.UpdateRootMap(diffResult);
46
106
  });
47
107
  }
108
+ /**
109
+ * Splices an array stored at the specified key with new data asynchronously.
110
+ * This method ensures that splice operations are queued and executed in a non-blocking manner.
111
+ * It modifies the array by deleting elements and inserting new ones at the specified position.
112
+ * @param key The key of the array to be spliced.
113
+ * @param start The position at which to start changing the array.
114
+ * @param deleteCount Optional number of elements to delete. If not provided, all elements from start to end will be deleted.
115
+ * @param items Optional elements to insert into the array.
116
+ * @returns The array of deleted elements.
117
+ */
48
118
  async Splice(key, start, deleteCount, ...items) {
49
119
  return await this.queue.Next(async () => {
50
120
  const arr = this.Get(key);
@@ -56,6 +126,10 @@ class StoreAsync extends store_1.Store {
56
126
  return spliceResult;
57
127
  });
58
128
  }
129
+ /**
130
+ * Destroys the StoreAsync instance, stopping the async queue and cleaning up the diff instance.
131
+ * This method should be called when the instance is no longer needed to free up resources.
132
+ */
59
133
  Destroy() {
60
134
  this.queue.Stop();
61
135
  this.diff.Destroy();