@microsoft/fast-html 1.0.0-alpha.42 → 1.0.0-alpha.43
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 {
|
|
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
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
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);
|