ember-data-model-fragments 6.0.0 → 6.0.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.
- package/CHANGELOG.md +27 -0
- package/addon/array/stateful.js +18 -0
- package/addon/attributes/array.js +1 -1
- package/addon/attributes/fragment-array.js +1 -1
- package/addon/record-data.js +29 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,33 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## v6.0.2 (2023-07-15)
|
|
15
|
+
|
|
16
|
+
#### :bug: Bug Fix
|
|
17
|
+
* [#474](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/474) fix(polymorphism): fix regression introduced with ember-data-model-fragments 6.0.0 where owner is not passed to typeKey function ([@VincentMolinie](https://github.com/VincentMolinie))
|
|
18
|
+
* [#472](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/472) Ensure changing arrays are notified. ([@deanmarano](https://github.com/deanmarano))
|
|
19
|
+
* [#469](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/469) Fix issue with reloading array records. ([@deanmarano](https://github.com/deanmarano))
|
|
20
|
+
|
|
21
|
+
#### :house: Internal
|
|
22
|
+
* [#473](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/473) chore(deps): bump semver from 5.7.1 to 5.7.2 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
|
23
|
+
|
|
24
|
+
#### Committers: 2
|
|
25
|
+
- Dean Marano ([@deanmarano](https://github.com/deanmarano))
|
|
26
|
+
- Vincent Molinié ([@VincentMolinie](https://github.com/VincentMolinie))
|
|
27
|
+
|
|
28
|
+
## v6.0.1 (2023-05-30)
|
|
29
|
+
|
|
30
|
+
#### :bug: Bug Fix
|
|
31
|
+
* [#466](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/466) Fix glimmer render error when creating fragment arrays ([@dwickern](https://github.com/dwickern))
|
|
32
|
+
|
|
33
|
+
#### :house: Internal
|
|
34
|
+
* [#465](https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/465) chore(deps): bump socket.io-parser from 4.2.2 to 4.2.3 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
|
35
|
+
|
|
36
|
+
#### Committers: 1
|
|
37
|
+
- Derek Wickern ([@dwickern](https://github.com/dwickern))
|
|
38
|
+
|
|
12
39
|
## v6.0.0 (2023-05-26)
|
|
13
40
|
|
|
14
41
|
#### :boom: Breaking Change
|
package/addon/array/stateful.js
CHANGED
|
@@ -81,6 +81,20 @@ const StatefulArray = EmberObject.extend(MutableArray, Copyable, {
|
|
|
81
81
|
return this._length;
|
|
82
82
|
},
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Unlike `setObjects`, this method avoids setting up auto-tracking,
|
|
86
|
+
* which prevents a glimmer rendering error in some circumstances.
|
|
87
|
+
* @see https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/466
|
|
88
|
+
* @param objects the new array contents
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
_setFragments(objects) {
|
|
92
|
+
if (this._isDirty) {
|
|
93
|
+
this.retrieveLatest();
|
|
94
|
+
}
|
|
95
|
+
this.replace(0, this._length, objects);
|
|
96
|
+
},
|
|
97
|
+
|
|
84
98
|
objectAt(index) {
|
|
85
99
|
if (this._isDirty) {
|
|
86
100
|
this.retrieveLatest();
|
|
@@ -97,6 +111,10 @@ const StatefulArray = EmberObject.extend(MutableArray, Copyable, {
|
|
|
97
111
|
'The third argument to replace needs to be an array.',
|
|
98
112
|
isArray(items)
|
|
99
113
|
);
|
|
114
|
+
if (deleteCount === 0 && items.length === 0) {
|
|
115
|
+
// array is unchanged
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
100
118
|
const data = this.currentState.slice();
|
|
101
119
|
data.splice(
|
|
102
120
|
start,
|
|
@@ -102,7 +102,7 @@ export default function fragmentArray(type, options) {
|
|
|
102
102
|
});
|
|
103
103
|
recordData._fragmentArrayCache[key] = fragmentArray;
|
|
104
104
|
}
|
|
105
|
-
fragmentArray.
|
|
105
|
+
fragmentArray._setFragments(value);
|
|
106
106
|
return fragmentArray;
|
|
107
107
|
},
|
|
108
108
|
}).meta(meta);
|
package/addon/record-data.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line ember/use-ember-data-rfc-395-imports
|
|
2
2
|
import { RecordData } from 'ember-data/-private';
|
|
3
|
+
import { diffArray } from '@ember-data/model/-private';
|
|
3
4
|
import { recordDataFor } from '@ember-data/store/-private';
|
|
4
5
|
import { assert } from '@ember/debug';
|
|
5
6
|
import { typeOf } from '@ember/utils';
|
|
@@ -603,7 +604,8 @@ export default class FragmentRecordData extends RecordData {
|
|
|
603
604
|
const type = getActualFragmentType(
|
|
604
605
|
definition.modelName,
|
|
605
606
|
definition.options,
|
|
606
|
-
attributes
|
|
607
|
+
attributes,
|
|
608
|
+
this._fragmentGetRecord()
|
|
607
609
|
);
|
|
608
610
|
const recordData = this.storeWrapper.recordDataFor(type);
|
|
609
611
|
recordData.setFragmentOwner(this, definition.name);
|
|
@@ -692,7 +694,11 @@ export default class FragmentRecordData extends RecordData {
|
|
|
692
694
|
if (this._fragments[key]) {
|
|
693
695
|
continue;
|
|
694
696
|
}
|
|
695
|
-
|
|
697
|
+
const eitherIsNull = original[key] === null || updates[key] === null;
|
|
698
|
+
if (
|
|
699
|
+
eitherIsNull ||
|
|
700
|
+
diffArray(original[key], updates[key]).firstChangeIndex !== null
|
|
701
|
+
) {
|
|
696
702
|
changedKeys.push(key);
|
|
697
703
|
}
|
|
698
704
|
}
|
|
@@ -701,12 +707,13 @@ export default class FragmentRecordData extends RecordData {
|
|
|
701
707
|
|
|
702
708
|
pushData(data, calculateChange) {
|
|
703
709
|
let changedFragmentKeys;
|
|
710
|
+
|
|
711
|
+
const subFragmentsToProcess = [];
|
|
704
712
|
if (data.attributes) {
|
|
705
713
|
// copy so that we don't mutate the caller's data
|
|
706
714
|
const attributes = Object.assign({}, data.attributes);
|
|
707
715
|
data = Object.assign({}, data, { attributes });
|
|
708
716
|
|
|
709
|
-
const newCanonicalFragments = {};
|
|
710
717
|
for (const [key, behavior] of Object.entries(this._fragmentBehavior)) {
|
|
711
718
|
const canonical = data.attributes[key];
|
|
712
719
|
if (canonical === undefined) {
|
|
@@ -715,25 +722,41 @@ export default class FragmentRecordData extends RecordData {
|
|
|
715
722
|
// strip fragments from the attributes so the super call does not process them
|
|
716
723
|
delete data.attributes[key];
|
|
717
724
|
|
|
725
|
+
subFragmentsToProcess.push({ key, behavior, canonical, attributes });
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Wee need first the attributes to be setup before the fragment, to be able to access them (for polymorphic fragments for example)
|
|
730
|
+
const changedAttributeKeys = super.pushData(data, calculateChange);
|
|
731
|
+
|
|
732
|
+
if (data.attributes) {
|
|
733
|
+
const newCanonicalFragments = {};
|
|
734
|
+
|
|
735
|
+
subFragmentsToProcess.forEach(({ key, behavior, canonical }) => {
|
|
718
736
|
const current =
|
|
719
737
|
key in this._fragmentData
|
|
720
738
|
? this._fragmentData[key]
|
|
721
739
|
: this._getFragmentDefault(key);
|
|
722
740
|
newCanonicalFragments[key] = behavior.pushData(current, canonical);
|
|
723
|
-
}
|
|
741
|
+
});
|
|
742
|
+
|
|
724
743
|
if (calculateChange) {
|
|
725
744
|
changedFragmentKeys = this._changedFragmentKeys(newCanonicalFragments);
|
|
726
745
|
}
|
|
746
|
+
|
|
727
747
|
Object.assign(this._fragmentData, newCanonicalFragments);
|
|
748
|
+
// update fragment arrays
|
|
749
|
+
changedFragmentKeys?.forEach((key) =>
|
|
750
|
+
this._fragmentArrayCache[key]?.notify()
|
|
751
|
+
);
|
|
728
752
|
}
|
|
729
753
|
|
|
730
|
-
const changedAttributeKeys = super.pushData(data, calculateChange);
|
|
731
754
|
const changedKeys = mergeArrays(changedAttributeKeys, changedFragmentKeys);
|
|
732
755
|
if (gte('ember-data', '4.5.0') && changedKeys?.length > 0) {
|
|
733
756
|
internalModelFor(this).notifyAttributes(changedKeys);
|
|
734
757
|
}
|
|
735
758
|
// on ember-data 2.8 - 4.4, InternalModel.setupData will notify
|
|
736
|
-
return changedKeys;
|
|
759
|
+
return changedKeys || [];
|
|
737
760
|
}
|
|
738
761
|
|
|
739
762
|
willCommit() {
|