@mintjamsinc/ichigojs 0.1.50 → 0.1.51

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.
@@ -8121,6 +8121,12 @@ class VBindings {
8121
8121
  * Flag to suppress onChange callbacks temporarily.
8122
8122
  */
8123
8123
  #suppressOnChange = false;
8124
+ /**
8125
+ * Per-instance path aliases. Maps local variable names to their reactive source paths.
8126
+ * Scoped here instead of the global ReactiveProxy map so that v-for items each maintain
8127
+ * their own alias (e.g. "file" -> "files[0]") without overwriting each other.
8128
+ */
8129
+ #localAliases = new Map();
8124
8130
  /**
8125
8131
  * Creates a new instance of VBindings.
8126
8132
  * @param parent The parent bindings, if any.
@@ -8155,7 +8161,7 @@ class VBindings {
8155
8161
  const existingPath = ReactiveProxy.getPath(value);
8156
8162
  if (existingPath) {
8157
8163
  // Register a path alias so changes to the source path will match this identifier
8158
- ReactiveProxy.registerPathAlias(key, existingPath);
8164
+ this.#localAliases.set(key, existingPath);
8159
8165
  this.#logger?.debug(`Path alias registered: ${key} -> ${existingPath}`);
8160
8166
  // Keep the existing proxy as-is to preserve reactivity chain
8161
8167
  newValue = value;
@@ -8170,7 +8176,7 @@ class VBindings {
8170
8176
  const propPath = ReactiveProxy.getPath(propValue);
8171
8177
  if (propPath) {
8172
8178
  // Register alias: key.propKey -> propPath
8173
- ReactiveProxy.registerPathAlias(`${key}.${propKey}`, propPath);
8179
+ this.#localAliases.set(`${key}.${propKey}`, propPath);
8174
8180
  this.#logger?.debug(`Property path alias registered: ${key}.${propKey} -> ${propPath}`);
8175
8181
  }
8176
8182
  }
@@ -8191,8 +8197,14 @@ class VBindings {
8191
8197
  }
8192
8198
  }
8193
8199
  else if (value === null || value === undefined) {
8194
- // When setting to null/undefined, unregister any path alias
8195
- ReactiveProxy.unregisterPathAlias(key);
8200
+ // When setting to null/undefined, remove local aliases for this key and nested paths
8201
+ for (const aliasKey of [...this.#localAliases.keys()]) {
8202
+ if (aliasKey === key ||
8203
+ aliasKey.startsWith(key + ".") ||
8204
+ aliasKey.startsWith(key + "[")) {
8205
+ this.#localAliases.delete(aliasKey);
8206
+ }
8207
+ }
8196
8208
  }
8197
8209
  const oldValue = Reflect.get(target, key);
8198
8210
  const result = Reflect.set(target, key, newValue);
@@ -8329,6 +8341,54 @@ class VBindings {
8329
8341
  markChanged(key) {
8330
8342
  this.#changes.add(key);
8331
8343
  }
8344
+ /**
8345
+ * Resolves a local path alias for the given identifier by walking up the bindings chain.
8346
+ * Returns the resolved source path, or undefined if no alias is found.
8347
+ */
8348
+ resolveAlias(identifier) {
8349
+ // Direct match in local aliases
8350
+ if (this.#localAliases.has(identifier)) {
8351
+ return this.#localAliases.get(identifier);
8352
+ }
8353
+ // Check if this is a nested path of a locally aliased variable (e.g. "file.isModified")
8354
+ for (const [alias, source] of this.#localAliases.entries()) {
8355
+ if (identifier.startsWith(alias + '.') || identifier.startsWith(alias + '[')) {
8356
+ return source + identifier.substring(alias.length);
8357
+ }
8358
+ }
8359
+ // Walk up the parent chain
8360
+ return this.#parent?.resolveAlias(identifier);
8361
+ }
8362
+ /**
8363
+ * Checks whether a reactive change path matches a given identifier, taking local path
8364
+ * aliases into account. Falls back to ReactiveProxy.doesChangeMatchIdentifier for
8365
+ * global aliases (computed properties etc.).
8366
+ */
8367
+ doesChangeMatchIdentifier(changePath, identifier) {
8368
+ // Direct match
8369
+ if (changePath === identifier) {
8370
+ return true;
8371
+ }
8372
+ // Resolve via local (scoped) alias chain
8373
+ const resolved = this.resolveAlias(identifier);
8374
+ if (resolved) {
8375
+ if (changePath === resolved) {
8376
+ return true;
8377
+ }
8378
+ // changePath is a descendant of resolved (e.g. "files[0].isModified" for resolved "files[0]")
8379
+ if (changePath.startsWith(resolved + '.') || changePath.startsWith(resolved + '[')) {
8380
+ return true;
8381
+ }
8382
+ // changePath is an ancestor of resolved (e.g. "files" for resolved "files[0].isModified")
8383
+ // This handles raw objects: when the parent collection is replaced/spliced, all item
8384
+ // properties are considered changed.
8385
+ if (resolved.startsWith(changePath + '.') || resolved.startsWith(changePath + '[')) {
8386
+ return true;
8387
+ }
8388
+ }
8389
+ // Fall back to global alias resolution (computed properties, etc.)
8390
+ return ReactiveProxy.doesChangeMatchIdentifier(changePath, identifier);
8391
+ }
8332
8392
  }
8333
8393
 
8334
8394
  // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
@@ -9045,7 +9105,7 @@ class VNode {
9045
9105
  if (this.#nodeType === Node.TEXT_NODE && this.#textEvaluator) {
9046
9106
  // If this is a text node with a text evaluator, update its content if needed
9047
9107
  // Check if any of the identifiers are in the changed identifiers (considering path aliases)
9048
- const changed = this.#textEvaluator.identifiers.some(id => changes.some(change => ReactiveProxy.doesChangeMatchIdentifier(change, id)));
9108
+ const changed = this.#textEvaluator.identifiers.some(id => changes.some(change => this.bindings.doesChangeMatchIdentifier(change, id)));
9049
9109
  // If the text node has changed, update its content
9050
9110
  if (changed) {
9051
9111
  const text = this.#node;
@@ -9068,7 +9128,7 @@ class VNode {
9068
9128
  }
9069
9129
  // Prepare bindings for each preparer if relevant identifiers have changed
9070
9130
  for (const preparer of this.#directiveManager.bindingsPreparers) {
9071
- const changed = preparer.dependentIdentifiers.some(id => changes.some(change => ReactiveProxy.doesChangeMatchIdentifier(change, id)));
9131
+ const changed = preparer.dependentIdentifiers.some(id => changes.some(change => this.bindings.doesChangeMatchIdentifier(change, id)));
9072
9132
  if (changed) {
9073
9133
  preparer.prepareBindings();
9074
9134
  }
@@ -9077,7 +9137,7 @@ class VNode {
9077
9137
  // Apply DOM updaters from directives, if any
9078
9138
  if (this.#directiveManager?.domUpdaters) {
9079
9139
  for (const updater of this.#directiveManager.domUpdaters) {
9080
- const changed = updater.dependentIdentifiers.some(id => changes.some(change => ReactiveProxy.doesChangeMatchIdentifier(change, id)));
9140
+ const changed = updater.dependentIdentifiers.some(id => changes.some(change => this.bindings.doesChangeMatchIdentifier(change, id)));
9081
9141
  if (changed) {
9082
9142
  updater.applyToDOM();
9083
9143
  }
@@ -9085,7 +9145,7 @@ class VNode {
9085
9145
  }
9086
9146
  // Recursively update dependent virtual nodes
9087
9147
  this.#dependents?.forEach(dependentNode => {
9088
- const changed = dependentNode.dependentIdentifiers.some(id => changes.some(change => ReactiveProxy.doesChangeMatchIdentifier(change, id)));
9148
+ const changed = dependentNode.dependentIdentifiers.some(id => changes.some(change => dependentNode.bindings.doesChangeMatchIdentifier(change, id)));
9089
9149
  if (changed) {
9090
9150
  dependentNode.update();
9091
9151
  }