@microsoft/fast-html 1.0.0-alpha.42 → 1.0.0-alpha.44

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.
@@ -1,6 +1,6 @@
1
1
  import { expect, test } from "@playwright/test";
2
2
  import { ObserverMap } from "./observer-map.js";
3
- import { Schema, defsPropertyName } from "./schema.js";
3
+ import { defsPropertyName, Schema } from "./schema.js";
4
4
  const testElementName = "test-class";
5
5
  test.describe("ObserverMap", async () => {
6
6
  let observerMap;
@@ -761,20 +761,27 @@ function getSchemaProperties(schema) {
761
761
  * @returns The array with observable properties and change notifications
762
762
  */
763
763
  function assignObservablesToArray(proxiedData, schema, rootSchema, target, rootProperty) {
764
- const data = proxiedData.map((item) => {
765
- const originalItem = Object.assign({}, item);
766
- assignProxyToItemsInArray(item, originalItem, schema, rootSchema);
767
- return Object.assign(item, originalItem);
768
- });
764
+ const schemaProperties = getSchemaProperties(schema);
765
+ // If the schema has no properties, the array contains primitives (e.g. string[])
766
+ // observe the array for changes but skip per-item proxying.
767
+ const data = schemaProperties
768
+ ? proxiedData.map((item) => {
769
+ const originalItem = Object.assign({}, item);
770
+ assignProxyToItemsInArray(item, originalItem, schema, rootSchema);
771
+ return Object.assign(item, originalItem);
772
+ })
773
+ : proxiedData;
769
774
  Observable.getNotifier(data).subscribe({
770
775
  handleChange(subject, args) {
771
776
  args.forEach((arg) => {
772
777
  if (arg.addedCount > 0) {
773
- for (let i = arg.addedCount - 1; i >= 0; i--) {
774
- const item = subject[arg.index + i];
775
- const originalItem = Object.assign({}, item);
776
- assignProxyToItemsInArray(item, originalItem, schema, rootSchema);
777
- Object.assign(item, originalItem);
778
+ if (schemaProperties) {
779
+ for (let i = arg.addedCount - 1; i >= 0; i--) {
780
+ const item = subject[arg.index + i];
781
+ const originalItem = Object.assign({}, item);
782
+ assignProxyToItemsInArray(item, originalItem, schema, rootSchema);
783
+ Object.assign(item, originalItem);
784
+ }
778
785
  }
779
786
  // Notify observers of the target object's root property
780
787
  Observable.notify(target, rootProperty);
@@ -782,7 +789,29 @@ function assignObservablesToArray(proxiedData, schema, rootSchema, target, rootP
782
789
  });
783
790
  },
784
791
  });
785
- return data;
792
+ if (schemaProperties !== null) {
793
+ return data;
794
+ }
795
+ // For primitive arrays, wrap in a Proxy so that direct index assignment
796
+ // (e.g. arr[0] = value) triggers FAST's splice-based change tracking and
797
+ // keeps repeat directives in sync. Object arrays are not wrapped because
798
+ // their items are individually proxied, and FAST's own push/splice/etc.
799
+ // already carry splice records — double-wrapping would produce duplicate
800
+ // splice notifications.
801
+ return new Proxy(data, {
802
+ set: (arr, prop, value) => {
803
+ const idx = typeof prop === "string" ? Number(prop) : NaN;
804
+ if (typeof prop !== "symbol" && Number.isInteger(idx) && idx >= 0) {
805
+ // splice() replaces the item in-place and creates the splice
806
+ // record that FAST's ArrayObserver delivers to repeat directives.
807
+ Array.prototype.splice.call(arr, idx, 1, value);
808
+ }
809
+ else {
810
+ arr[prop] = value;
811
+ }
812
+ return true;
813
+ },
814
+ });
786
815
  }
787
816
  /**
788
817
  * Extracts the definition name from a JSON Schema $ref property
@@ -859,6 +888,12 @@ export function assignObservables(schema, rootSchema, data, target, rootProperty
859
888
  }));
860
889
  }
861
890
  }
891
+ else {
892
+ // Primitive array (items have no schema $ref): wrap in a proxy so that
893
+ // direct index assignments (e.g. arr[0] = value) use FAST's splice-based
894
+ // change tracking and keep repeat directives in sync.
895
+ proxiedData = assignObservablesToArray(proxiedData, schema, rootSchema, target, rootProperty);
896
+ }
862
897
  break;
863
898
  }
864
899
  case "object": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/fast-html",
3
- "version": "1.0.0-alpha.42",
3
+ "version": "1.0.0-alpha.44",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Microsoft",