@mintjamsinc/ichigojs 0.1.0 → 0.1.2

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.
@@ -31,7 +31,7 @@ export declare class VApplication {
31
31
  /**
32
32
  * Gets the bindings for the virtual application.
33
33
  */
34
- get bindings(): VBindings;
34
+ get bindings(): VBindings | undefined;
35
35
  /**
36
36
  * Gets the log manager.
37
37
  */
@@ -40,27 +40,9 @@ export declare class VApplication {
40
40
  * Gets the function dependencies for the virtual application.
41
41
  */
42
42
  get functionDependencies(): Record<string, string[]>;
43
- /**
44
- * Gets the list of identifiers that can trigger updates.
45
- */
46
- get preparableIdentifiers(): string[];
47
43
  /**
48
44
  * Mounts the application.
49
45
  * @param selectors The CSS selectors to identify the root element.
50
46
  */
51
47
  mount(selectors: string): void;
52
- /**
53
- * Schedules a DOM update in the next microtask.
54
- * Multiple calls within the same event loop will be batched into a single update.
55
- */
56
- scheduleUpdate(): void;
57
- /**
58
- * Executes an immediate DOM update.
59
- */
60
- update(): void;
61
- /**
62
- * Executes a callback after the next DOM update.
63
- * @param callback The callback to execute.
64
- */
65
- nextTick(callback: () => void): void;
66
48
  }
@@ -1,9 +1,59 @@
1
+ import { VBindingsInit } from "./VBindingsInit";
1
2
  /**
2
3
  * A dictionary representing bindings for a virtual node.
4
+ * The key is the binding name, and the value is the binding value.
5
+ * Supports hierarchical lookup through parent bindings.
3
6
  */
4
- export interface VBindings {
7
+ export declare class VBindings {
8
+ #private;
5
9
  /**
6
- * The key is the binding name, and the value is the binding value.
10
+ * Creates a new instance of VBindings.
11
+ * @param parent The parent bindings, if any.
7
12
  */
8
- [key: string]: any;
13
+ constructor(args?: VBindingsInit);
14
+ /**
15
+ * Gets the raw bindings.
16
+ * If a key is not found locally, it searches parent bindings recursively.
17
+ */
18
+ get raw(): Record<string, any>;
19
+ /**
20
+ * Indicates whether there are any changed identifiers.
21
+ */
22
+ get hasChanges(): boolean;
23
+ /**
24
+ * Gets the list of changed identifiers.
25
+ */
26
+ get changes(): string[];
27
+ /**
28
+ * Indicates whether this is the root bindings (i.e., has no parent).
29
+ */
30
+ get isRoot(): boolean;
31
+ /**
32
+ * Clears the set of changed identifiers.
33
+ */
34
+ clearChanges(): void;
35
+ /**
36
+ * Sets a binding value.
37
+ * @param key The binding name.
38
+ * @param value The binding value.
39
+ */
40
+ set(key: string, value: any): void;
41
+ /**
42
+ * Gets a binding value.
43
+ * @param key The binding name.
44
+ * @returns The binding value, or undefined if not found.
45
+ */
46
+ get(key: string): any;
47
+ /**
48
+ * Checks if a binding exists.
49
+ * @param key The binding name.
50
+ * @param recursive Whether to search parent bindings. Default is true.
51
+ * @returns True if the binding exists, false otherwise.
52
+ */
53
+ has(key: string, recursive?: boolean): boolean;
54
+ /**
55
+ * Removes a local binding.
56
+ * @param key The binding name.
57
+ */
58
+ remove(key: string): void;
9
59
  }
@@ -0,0 +1,15 @@
1
+ import { VBindings } from "./VBindings";
2
+ /**
3
+ * Initialization arguments for bindings.
4
+ */
5
+ export interface VBindingsInit {
6
+ /**
7
+ * The parent bindings, if any.
8
+ */
9
+ parent?: VBindings;
10
+ /**
11
+ * The change tracker, if any.
12
+ * @param identifier The identifier that changed.
13
+ */
14
+ onChange?: (identifier: string) => void;
15
+ }
@@ -1,13 +1,12 @@
1
- import { VBindings } from "./VBindings";
2
1
  /**
3
2
  * Interface representing a preparer for VBindings in the virtual DOM.
4
3
  */
5
4
  export interface VBindingsPreparer {
6
5
  /**
7
- * The list of identifiers that this preparer is concerned with.
8
- * These identifiers are used to determine when the bindings need to be prepared.
6
+ * The list of identifiers that this preparer depends on.
7
+ * Changes to these identifiers may trigger the need to prepare bindings again.
9
8
  */
10
- get identifiers(): string[];
9
+ get dependentIdentifiers(): string[];
11
10
  /**
12
11
  * The list of identifiers that can be prepared by this preparer.
13
12
  * This is a subset of the identifiers property.
@@ -17,7 +16,6 @@ export interface VBindingsPreparer {
17
16
  * Prepares the given VBindings for use in the virtual DOM.
18
17
  * This method is called before the bindings are applied to the DOM.
19
18
  * It allows for any necessary transformations or initializations of the bindings.
20
- * @param bindings The original VBindings to be prepared.
21
19
  */
22
- prepareBindings(bindings: VBindings): void;
20
+ prepareBindings(): void;
23
21
  }
@@ -5,10 +5,10 @@
5
5
  */
6
6
  export interface VDOMUpdater {
7
7
  /**
8
- * A list of variable and function names that this updater is concerned with.
8
+ * The list of identifiers that this updater depends on.
9
9
  * Changes to these identifiers may trigger the updater to apply changes to the DOM.
10
10
  */
11
- get identifiers(): string[];
11
+ get dependentIdentifiers(): string[];
12
12
  /**
13
13
  * Applies the changes from the virtual DOM to the actual DOM.
14
14
  * This method is called when the identifiers change or when an update is needed.
@@ -3,7 +3,11 @@ import { VBindings } from "./VBindings";
3
3
  import { VCloser } from "./VCloser";
4
4
  import { VDirectiveManager } from "./directives/VDirectiveManager";
5
5
  import { VNodeInit } from "./VNodeInit";
6
- import { VUpdateContext } from "./VUpdateContext";
6
+ /**
7
+ * Represents a virtual node in the virtual DOM.
8
+ * A virtual node corresponds to a real DOM node and contains additional information for data binding and directives.
9
+ * This class is responsible for managing the state and behavior of the virtual node, including its bindings, directives, and child nodes.
10
+ */
7
11
  export declare class VNode {
8
12
  #private;
9
13
  /**
@@ -50,7 +54,7 @@ export declare class VNode {
50
54
  /**
51
55
  * The data bindings associated with this virtual node, if any.
52
56
  */
53
- get bindings(): VBindings | undefined;
57
+ get bindings(): VBindings;
54
58
  /**
55
59
  * The directive manager associated with this virtual node.
56
60
  * This manages any directives applied to the node.
@@ -78,22 +82,44 @@ export declare class VNode {
78
82
  * The list of identifiers for this virtual node.
79
83
  * This includes variable and function names used in expressions.
80
84
  */
81
- get identifiers(): string[];
85
+ get dependentIdentifiers(): string[];
82
86
  get preparableIdentifiers(): string[];
87
+ /**
88
+ * The DOM path of this virtual node.
89
+ * This is a string representation of the path from the root to this node,
90
+ * using the node names and their indices among siblings with the same name.
91
+ * For example: "DIV[0]/SPAN[1]/#text[0]"
92
+ * @return The DOM path as a string.
93
+ */
94
+ get domPath(): string;
83
95
  /**
84
96
  * Updates the virtual node and its children based on the current bindings.
85
97
  * This method evaluates any expressions in text nodes and applies effectors from directives.
86
98
  * It also recursively updates child virtual nodes.
87
99
  * @param context The context for the update operation.
100
+ * This includes the current bindings and a list of identifiers that have changed.
101
+ */
102
+ update(): void;
103
+ /**
104
+ * Forces an update of the virtual node and its children, regardless of changed identifiers.
105
+ * This method evaluates any expressions in text nodes and applies effectors from directives.
106
+ * It also recursively updates child virtual nodes.
107
+ * This is useful when an immediate update is needed, bypassing the usual change detection.
108
+ */
109
+ forceUpdate(): void;
110
+ /**
111
+ * Adds a child virtual node to this virtual node.
112
+ * @param child The child virtual node to add.
88
113
  */
89
- update(context: VUpdateContext): void;
114
+ addChild(child: VNode): void;
90
115
  /**
91
- * Adds a dependency on the specified virtual node.
92
- * This means that if the specified node's bindings change, this node may need to be updated.
93
- * @param dependentNode The virtual node to add as a dependency.
116
+ * Adds a dependent virtual node that relies on this node's bindings.
117
+ * @param dependent The dependent virtual node to add.
118
+ * @param dependentIdentifiers The identifiers that the dependent node relies on.
119
+ * If not provided, the dependent node's own identifiers will be used.
94
120
  * @returns A list of closers to unregister the dependency, or undefined if no dependency was added.
95
121
  */
96
- addDependency(dependentNode: VNode): VCloser[] | undefined;
122
+ addDependent(dependent: VNode, dependentIdentifiers?: string[] | undefined): VCloser[] | undefined;
97
123
  /**
98
124
  * Cleans up any resources used by this virtual node.
99
125
  * This method is called when the virtual node is no longer needed.
@@ -1,6 +1,5 @@
1
1
  import { VApplication } from "./VApplication";
2
2
  import { VBindings } from "./VBindings";
3
- import { VBindingsPreparer } from "./VBindingsPreparer";
4
3
  import { VNode } from "./VNode";
5
4
  /**
6
5
  * Initialization arguments for a virtual node.
@@ -19,11 +18,13 @@ export interface VNodeInit {
19
18
  */
20
19
  parentVNode?: VNode;
21
20
  /**
22
- * The data bindings associated with this virtual node.
21
+ * The bindings associated with this virtual node.
22
+ * This is optional and may be undefined if there are no bindings.
23
23
  */
24
- bindings: VBindings;
24
+ bindings?: VBindings;
25
25
  /**
26
- * The preparer for VBindings, if any.
26
+ * The set of identifiers that this node depends on.
27
+ * This is optional and may be undefined if there are no dependent identifiers.
27
28
  */
28
- bindingsPreparer?: VBindingsPreparer;
29
+ dependentIdentifiers?: string[];
29
30
  }
@@ -44,6 +44,14 @@ export declare class VBindDirective implements VDirective {
44
44
  * @inheritdoc
45
45
  */
46
46
  get domUpdater(): VDOMUpdater | undefined;
47
+ /**
48
+ * @inheritdoc
49
+ */
50
+ get templatize(): boolean;
51
+ /**
52
+ * @inheritdoc
53
+ */
54
+ get dependentIdentifiers(): string[];
47
55
  /**
48
56
  * Indicates if this directive is binding the "key" attribute.
49
57
  * The "key" attribute is special and is used for optimizing rendering of lists.
@@ -30,6 +30,14 @@ export declare abstract class VConditionalDirective implements VDirective {
30
30
  * @inheritdoc
31
31
  */
32
32
  get domUpdater(): VDOMUpdater | undefined;
33
+ /**
34
+ * @inheritdoc
35
+ */
36
+ get templatize(): boolean;
37
+ /**
38
+ * @inheritdoc
39
+ */
40
+ get dependentIdentifiers(): string[];
33
41
  /**
34
42
  * The context for managing related conditional directives (v-if, v-else-if, v-else).
35
43
  */
@@ -4,6 +4,11 @@ import { VConditionalDirective } from "./VConditionalDirective";
4
4
  */
5
5
  export declare class VConditionalDirectiveContext {
6
6
  #private;
7
+ /**
8
+ * Gets a list of all variable and function names used in the expressions of the associated directives.
9
+ * This is useful for determining dependencies for re-evaluation when data changes.
10
+ */
11
+ get allDependentIdentifiers(): string[];
7
12
  /**
8
13
  * Adds a directive (v-else-if or v-else) to the conditional context.
9
14
  * @param directive The directive to add.
@@ -40,6 +40,23 @@ export interface VDirective {
40
40
  * If the directive does not need to update the DOM, this may return undefined.
41
41
  */
42
42
  get domUpdater(): VDOMUpdater | undefined;
43
+ /**
44
+ * Indicates whether this directive requires the template content to be preserved.
45
+ * If true, the original template content will be kept intact and used as needed by the directive.
46
+ * This is typically true for directives that need to re-render or clone the template content,
47
+ * such as v-for and v-if.
48
+ * If false, the template content may be modified or removed as part of the directive's processing.
49
+ * Directives that do not need to preserve the original template content should return false.
50
+ * This property is used by the VNode to determine how to handle the template content.
51
+ * Note: This property should be implemented as a getter to allow dynamic evaluation based on directive state.
52
+ */
53
+ get templatize(): boolean;
54
+ /**
55
+ * Gets the list of dependent identifiers for this directive.
56
+ * These are the variable and function names that the directive depends on.
57
+ * @returns An array of dependent identifier names.
58
+ */
59
+ get dependentIdentifiers(): string[];
43
60
  /**
44
61
  * Cleans up any resources used by the directive.
45
62
  * This method is called when the directive is no longer needed.
@@ -44,6 +44,14 @@ export declare class VForDirective implements VDirective {
44
44
  * @inheritdoc
45
45
  */
46
46
  get domUpdater(): VDOMUpdater | undefined;
47
+ /**
48
+ * @inheritdoc
49
+ */
50
+ get templatize(): boolean;
51
+ /**
52
+ * @inheritdoc
53
+ */
54
+ get dependentIdentifiers(): string[];
47
55
  /**
48
56
  * @inheritdoc
49
57
  */
@@ -40,6 +40,14 @@ export declare class VModelDirective implements VDirective {
40
40
  * @inheritdoc
41
41
  */
42
42
  get domUpdater(): VDOMUpdater | undefined;
43
+ /**
44
+ * @inheritdoc
45
+ */
46
+ get templatize(): boolean;
47
+ /**
48
+ * @inheritdoc
49
+ */
50
+ get dependentIdentifiers(): string[];
43
51
  /**
44
52
  * @inheritdoc
45
53
  */
@@ -42,6 +42,14 @@ export declare class VOnDirective implements VDirective {
42
42
  * @inheritdoc
43
43
  */
44
44
  get domUpdater(): VDOMUpdater | undefined;
45
+ /**
46
+ * @inheritdoc
47
+ */
48
+ get templatize(): boolean;
49
+ /**
50
+ * @inheritdoc
51
+ */
52
+ get dependentIdentifiers(): string[];
45
53
  /**
46
54
  * @inheritdoc
47
55
  */
@@ -39,6 +39,14 @@ export declare class VShowDirective implements VDirective {
39
39
  * @inheritdoc
40
40
  */
41
41
  get domUpdater(): VDOMUpdater | undefined;
42
+ /**
43
+ * @inheritdoc
44
+ */
45
+ get templatize(): boolean;
46
+ /**
47
+ * @inheritdoc
48
+ */
49
+ get dependentIdentifiers(): string[];
42
50
  /**
43
51
  * Makes the node visible by resetting its display style.
44
52
  * If the node is already visible, no action is taken.
@@ -3,19 +3,20 @@
3
3
  */
4
4
  export declare class ReactiveProxy {
5
5
  /**
6
- * A WeakMap to store the original target for each proxy.
7
- * This allows us to avoid creating multiple proxies for the same object.
6
+ * A WeakMap to store the proxy for each target object and path combination.
7
+ * This prevents creating multiple proxies for the same object accessed from different paths.
8
8
  */
9
- private static proxyMap;
9
+ private static proxyCache;
10
10
  /**
11
11
  * Creates a reactive proxy for the given object.
12
12
  * The proxy will call the onChange callback whenever a property is modified.
13
13
  *
14
14
  * @param target The object to make reactive.
15
- * @param onChange Callback function to call when the object changes. Receives the changed key name.
15
+ * @param onChange Callback function to call when the object changes. Receives the full path of the changed property.
16
+ * @param path The current path in the object tree (used internally for nested objects).
16
17
  * @returns A reactive proxy of the target object.
17
18
  */
18
- static create<T extends object>(target: T, onChange: (changedKey?: string) => void): T;
19
+ static create<T extends object>(target: T, onChange: (changedPath?: string) => void, path?: string): T;
19
20
  /**
20
21
  * Checks if the given object is a reactive proxy.
21
22
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintjamsinc/ichigojs",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "ichigo.js - Simple and intuitive reactive framework. Lightweight, fast, and user-friendly virtual DOM library",
5
5
  "main": "./dist/ichigo.umd.js",
6
6
  "module": "./dist/ichigo.esm.js",
@@ -11,7 +11,7 @@
11
11
  "homepage": "https://github.com/mintjamsinc/ichigojs#readme",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/mintjamsinc/ichigojs.git"
14
+ "url": "git+https://github.com/mintjamsinc/ichigojs.git"
15
15
  },
16
16
  "bugs": {
17
17
  "url": "https://github.com/mintjamsinc/ichigojs/issues"