j-templates 7.0.65 → 7.0.67

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.
@@ -169,7 +169,9 @@ exports.DOMNodeConfig = {
169
169
  target.appendChild(children[x]);
170
170
  },
171
171
  reconcileChild(target, child) {
172
- if (target.childElementCount > 1 || target.firstChild !== child)
172
+ if (target.childElementCount === 0)
173
+ target.appendChild(child);
174
+ else if (target.childElementCount > 1 || target.firstChild !== child)
173
175
  target.replaceChildren(child);
174
176
  },
175
177
  };
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
+ // }
@@ -1,22 +1,74 @@
1
1
  import { ComponentEvents } from "./component.types";
2
- import { ObservableScope } from "../Store/Tree/observableScope";
3
2
  import { FunctionOr, vNode as vNodeType } from "./vNode.types";
4
3
  import { RecursivePartial } from "../Utils/utils.types";
4
+ import { IObservableScope } from "../Store/Tree/observableScope";
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;
12
- protected get Scope(): ObservableScope<D>;
13
- protected get Data(): D;
25
+ /**
26
+ * Internal scoped Observable for component state.
27
+ */
28
+ protected get Scope(): IObservableScope<D | Promise<D>>;
29
+ /**
30
+ * Current data value from the scoped Observable.
31
+ */
32
+ protected get Data(): D | Promise<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
@@ -2,69 +2,164 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Component = void 0;
4
4
  const decorators_1 = require("../Utils/decorators");
5
- const observableScope_1 = require("../Store/Tree/observableScope");
6
5
  const vNode_1 = require("./vNode");
6
+ const Store_1 = require("../Store");
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
- return this.scope.Value;
37
+ return Store_1.ObservableScope.Value(this.scope);
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;
74
+ /* if (typeof data === "function")
75
+ this.scope = new ObservableScope<D>(data as () => D | Promise<D>);
76
+ else this.scope = new ObservableScope<D>(() => data); */
29
77
  if (typeof data === "function")
30
- this.scope = new observableScope_1.ObservableScope(data);
78
+ this.scope = Store_1.ObservableScope.Create(data);
31
79
  else
32
- this.scope = new observableScope_1.ObservableScope(() => data);
80
+ this.scope = {
81
+ type: "static",
82
+ value: data,
83
+ };
84
+ this.componentEvents = on;
33
85
  this.templates = templates || {};
34
86
  }
87
+ /**
88
+ * Returns the component's rendered vNode(s).
89
+ * Override to provide custom rendering logic.
90
+ *
91
+ * @returns A vNode or array of vNodes representing the component UI.
92
+ */
35
93
  Template() {
36
94
  return [];
37
95
  }
38
- Bound() { }
96
+ /**
97
+ * Lifecycle hook called after the component has been bound to the DOM.
98
+ * Override to perform post‑binding initialization.
99
+ */
100
+ Bound() {
101
+ decorators_1.Bound.All(this);
102
+ }
103
+ /**
104
+ * Fires a component event.
105
+ *
106
+ * @param event - The event name to fire.
107
+ * @param data - Optional payload for the event.
108
+ */
39
109
  Fire(event, data) {
40
110
  var eventCallback = this.componentEvents && this.componentEvents[event];
41
111
  eventCallback && eventCallback(data);
42
112
  }
113
+ /**
114
+ * Destroys the component, cleaning up its scoped data and decorators.
115
+ */
43
116
  Destroy() {
44
- this.scope.Destroy();
117
+ Store_1.ObservableScope.Destroy(this.scope);
45
118
  decorators_1.Destroy.All(this);
46
119
  }
47
120
  }
48
121
  exports.Component = Component;
122
+ /* type ComponentConstructor<D, T, E> = {
123
+ new (
124
+ data: D | (() => D | Promise<D>),
125
+ templates: T,
126
+ vNode: vNodeType,
127
+ componentEvents: ComponentEvents<E>,
128
+ ): Component<D, T, E>;
129
+ }; */
49
130
  (function (Component) {
50
- function ToFunction(type, constructor, namespace) {
131
+ /**
132
+ * Function wraps the Component as a function that can be used to create vNode objects
133
+ * and generate templates.
134
+ */
135
+ function ToFunction(type,
136
+ // constructor: ComponentConstructor<D, T, E>,
137
+ constructor, namespace) {
51
138
  return function (config, templates) {
52
- const { data, on, props } = config;
139
+ /* const { data, on, props } = config;
140
+
53
141
  class ConcreteComponent extends constructor {
54
- constructor(vnode) {
55
- super(data, templates, vnode, on);
56
- }
142
+ constructor(vnode: vNodeType) {
143
+ super(data, templates, vnode, on);
144
+ }
145
+ } */
146
+ function ComponentFactory(vnode) {
147
+ return new constructor(vnode, config, templates);
57
148
  }
58
149
  const definition = {
59
150
  type,
60
151
  namespace: namespace ?? null,
61
- props,
62
- componentConstructor: ConcreteComponent,
152
+ props: config.props,
153
+ componentFactory: ComponentFactory,
154
+ // componentConstructor: ConcreteComponent,
63
155
  };
64
156
  return vNode_1.vNode.Create(definition);
65
157
  };
66
158
  }
67
159
  Component.ToFunction = ToFunction;
160
+ /**
161
+ * Function registers the Component as a WebComponent as the provided name.
162
+ */
68
163
  function Register(name, constructor) {
69
164
  const componentFunction = ToFunction(`${name}-component`, constructor);
70
165
  class WebComponent extends HTMLElement {
@@ -78,6 +173,13 @@ exports.Component = Component;
78
173
  customElements.define(name, WebComponent);
79
174
  }
80
175
  Component.Register = Register;
176
+ /**
177
+ * Attaches a virtual node to a real DOM node.
178
+ *
179
+ * @param node - The target DOM node to attach to.
180
+ * @param vnode - The virtual node to be attached.
181
+ * @returns The result of the attachment operation.
182
+ */
81
183
  function Attach(node, vnode) {
82
184
  return vNode_1.vNode.Attach(node, vnode);
83
185
  }
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,19 +95,22 @@ 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;
101
104
  if (props) {
102
105
  const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
103
106
  if (typeof props === "function") {
104
- const [value, scope] = Store_1.ObservableScope.CreateIf(props);
105
- if (scope) {
106
- vnode.scopes.push(scope);
107
- Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
108
- }
109
- assignProperties(value);
107
+ const scope = Store_1.ObservableScope.Create(props);
108
+ // const [value, scope] = ObservableScope.CreateIf(props as () => any);
109
+ // if (scope) {
110
+ vnode.scopes.push(scope);
111
+ Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
112
+ // }
113
+ assignProperties(Store_1.ObservableScope.Value(scope));
110
114
  }
111
115
  else
112
116
  assignProperties(props);
@@ -114,12 +118,13 @@ function InitNode(vnode) {
114
118
  if (on) {
115
119
  const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
116
120
  if (typeof on === "function") {
117
- const [value, scope] = Store_1.ObservableScope.CreateIf(on);
118
- if (scope) {
119
- vnode.scopes.push(scope);
120
- Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
121
- }
122
- assignEvents(value);
121
+ const scope = Store_1.ObservableScope.Create(on);
122
+ // const [value, scope] = ObservableScope.CreateIf(on);
123
+ // if (scope) {
124
+ vnode.scopes.push(scope);
125
+ Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
126
+ // }
127
+ assignEvents(Store_1.ObservableScope.Value(scope));
123
128
  }
124
129
  else
125
130
  assignEvents(on);
@@ -127,18 +132,21 @@ function InitNode(vnode) {
127
132
  if (attrs) {
128
133
  const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
129
134
  if (typeof attrs === "function") {
130
- const [value, scope] = Store_1.ObservableScope.CreateIf(attrs);
131
- if (scope) {
132
- vnode.scopes.push(scope);
133
- Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
134
- }
135
- assignAttributes(value);
135
+ const scope = Store_1.ObservableScope.Create(attrs);
136
+ // const [value, scope] = ObservableScope.CreateIf(attrs);
137
+ // if (scope) {
138
+ vnode.scopes.push(scope);
139
+ Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
140
+ //}
141
+ assignAttributes(Store_1.ObservableScope.Value(scope));
136
142
  }
137
143
  else
138
144
  assignAttributes(attrs);
139
145
  }
140
- if (componentConstructor) {
141
- vnode.component = new componentConstructor(vnode);
146
+ // if (componentConstructor) {
147
+ if (componentFactory) {
148
+ // vnode.component = new componentConstructor(vnode);
149
+ vnode.component = componentFactory(vnode);
142
150
  vnode.component.Bound();
143
151
  function componentChildren() {
144
152
  return vnode.component.Template();
@@ -155,7 +163,7 @@ function InitNode(vnode) {
155
163
  UpdateChildren(vnode, true, !!childrenArray);
156
164
  }
157
165
  function Children(vnode, children, data) {
158
- const [childNodes, childrenScope] = CreateChildrenScope(vnode, children, data);
166
+ const childrenScope = CreateChildrenScope(vnode, children, data);
159
167
  if (childrenScope) {
160
168
  vnode.scopes.push(childrenScope);
161
169
  Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function (scope) {
@@ -163,18 +171,29 @@ function Children(vnode, children, data) {
163
171
  return;
164
172
  const startChildren = vnode.children;
165
173
  const newChildren = Store_1.ObservableScope.Value(scope);
174
+ // AssignChildren(vnode, scope);
166
175
  if (startChildren !== newChildren) {
167
176
  vnode.children = newChildren;
168
177
  UpdateChildren(vnode);
169
178
  }
170
179
  }));
171
180
  }
172
- vnode.children = childNodes;
173
- }
174
- function AssignChildren(vnode, childrenScope) {
175
- const children = Store_1.ObservableScope.Peek(childrenScope);
176
- vnode.children = children;
181
+ vnode.children = Store_1.ObservableScope.Value(childrenScope);
182
+ // AssignChildren(vnode, childrenScope);
177
183
  }
184
+ /* function AssignChildren(
185
+ vnode: vNodeType,
186
+ childrenScope: IObservableScope<
187
+ [
188
+ any,
189
+ vNodeType[],
190
+ IObservableScope<string | vNodeType | vNodeType[]> | null,
191
+ ][]
192
+ >,
193
+ ) {
194
+ const children = ObservableScope.Peek(childrenScope);
195
+ vnode.children = children;
196
+ } */
178
197
  const DEFAULT_DATA = [undefined];
179
198
  function DefaultData() {
180
199
  return DEFAULT_DATA;
@@ -188,7 +207,7 @@ function CreateChildrenScope(vnode, children, data = DefaultData) {
188
207
  });
189
208
  };
190
209
  }
191
- return Store_1.ObservableScope.CreateIf(WrapChildren(vnode.injector, children, data));
210
+ return Store_1.ObservableScope.Create(WrapChildren(vnode.injector, children, data));
192
211
  }
193
212
  function WrapChildren(injector, children, data) {
194
213
  let nodeArray = [];
@@ -249,10 +268,14 @@ function EvaluateNextNodesSmall(injector, getNextChildren, nextData, nodeArray)
249
268
  nodeArray[i] = null;
250
269
  }
251
270
  else {
252
- const [nextChildren, scope] = Store_1.ObservableScope.CreateIf(function () {
271
+ const scope = Store_1.ObservableScope.Create(function () {
253
272
  return injector_1.Injector.Scope(injector, getNextChildren, data);
254
273
  });
255
- nextNodes[x] = [data, CreateNodeArray(nextChildren), scope];
274
+ nextNodes[x] = [
275
+ data,
276
+ CreateNodeArray(Store_1.ObservableScope.Value(scope)),
277
+ scope,
278
+ ];
256
279
  }
257
280
  }
258
281
  for (let x = 0; x < nodeArray.length; x++) {
@@ -278,27 +301,37 @@ function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray)
278
301
  for (; currentChildIndex >= 0 && currentChildren[currentChildIndex] === null; currentChildIndex--) { }
279
302
  if (currentChildIndex !== -1) {
280
303
  const currentChild = currentChildren[currentChildIndex];
281
- if (currentChild[2]) {
282
- const scope = currentChild[2];
283
- const value = scope.value;
284
- const updatedValue = Store_1.ObservableScope.Value(scope);
285
- if (value !== updatedValue)
286
- currentChild[1] = CreateNodeArray(updatedValue);
287
- }
288
- if (currentChild[2]?.dirty) {
289
- const nextChildren = Store_1.ObservableScope.Value(currentChild[2]);
290
- currentChild[1] = CreateNodeArray(nextChildren);
304
+ currentChildren[currentChildIndex] = null;
305
+ // if (currentChild[2]) {
306
+ const scope = currentChild[2];
307
+ const value = scope.value;
308
+ const updatedValue = Store_1.ObservableScope.Value(scope);
309
+ if (value !== updatedValue) {
310
+ vNode.DestroyAll(currentChild[1]);
311
+ currentChild[1] = CreateNodeArray(updatedValue);
291
312
  }
313
+ // }
314
+ /* if (currentChild[2]?.dirty) {
315
+ const nextChildren = ObservableScope.Value(currentChild[2]);
316
+ currentChild[1] = CreateNodeArray(nextChildren);
317
+ } */
292
318
  nextNodes[x] = currentChild;
293
- currentChildren[currentChildIndex] = null;
319
+ // currentChildren[currentChildIndex] = null;
294
320
  if (currentChildIndex === 0)
295
321
  dataMap.delete(data);
296
322
  }
297
323
  else {
298
- const [nextChildren, scope] = Store_1.ObservableScope.CreateIf(function () {
324
+ const scope = Store_1.ObservableScope.Create(function () {
299
325
  return injector_1.Injector.Scope(injector, getNextChildren, data);
300
326
  });
301
- nextNodes[x] = [data, CreateNodeArray(nextChildren), scope];
327
+ /* const [nextChildren, scope] = ObservableScope.CreateIf(function () {
328
+ return Injector.Scope(injector, getNextChildren, data);
329
+ }); */
330
+ nextNodes[x] = [
331
+ data,
332
+ CreateNodeArray(Store_1.ObservableScope.Value(scope)),
333
+ scope,
334
+ ];
302
335
  }
303
336
  }
304
337
  for (const value of dataMap.values()) {
@@ -378,8 +411,7 @@ function ScheduledAssignment(assign) {
378
411
  return;
379
412
  scheduled = true;
380
413
  nodeConfig_1.NodeConfig.scheduleUpdate(function () {
381
- if (scope.destroyed)
382
- return;
414
+ // if (scope.destroyed) return;
383
415
  scheduled = false;
384
416
  const value = Store_1.ObservableScope.Peek(scope);
385
417
  assign(value);
@@ -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
  }