@xh/hoist 78.0.0-SNAPSHOT.1761929921002 → 78.0.0-SNAPSHOT.1762216163824

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## 78.0.0-SNAPSHOT - unreleased
4
4
 
5
+ ### 🎁 New Features
6
+ * New method `StoreRecord.getModifiedValues()` to gather edited data from a store record.
7
+
8
+ ### 🐞 Bug Fixes
9
+ * StoreRecord will no longer report `isModified` as `true` if a field has been edited and
10
+ then returned to its original value in a subsequent edit.
11
+
5
12
  ## 77.0.1 - 2025-10-29
6
13
 
7
14
  ### 💥 Breaking Changes
@@ -35,12 +35,12 @@ export interface PersistOptions {
35
35
  viewManagerModel?: ViewManagerModel;
36
36
  /**
37
37
  * Function returning blob of data to be used for reading state.
38
- * Ignored if `prefKey`, `localStorageKey` or `dashViewModel` are provided.
38
+ * Ignored if `prefKey`, `localStorageKey`, `dashViewModel` or 'viewManagerModel' are provided.
39
39
  */
40
40
  getData?: () => any;
41
41
  /**
42
42
  * Function to be used to write blob of data representing state.
43
- * Ignored if `prefKey`, `localStorageKey` or `dashViewModel` are provided.
43
+ * Ignored if `prefKey`, `localStorageKey`, `dashViewModel` or 'viewManagerModel' are provided.
44
44
  */
45
45
  setData?: (data: object) => void;
46
46
  }
@@ -94,6 +94,14 @@ export declare class StoreRecord {
94
94
  * Field in the Store. Useful for cloning/iterating over all values (including defaults).
95
95
  */
96
96
  getValues(): PlainObject;
97
+ /**
98
+ * Get a map of modified values only.
99
+ *
100
+ * If record has no modifications, this method will return null.
101
+ * If modifications are returned, the returned object will include id,
102
+ * for convenience.
103
+ */
104
+ getModifiedValues(): PlainObject;
97
105
  /**
98
106
  * Construct a StoreRecord from a pre-processed `data` source object.
99
107
  *
@@ -59,13 +59,13 @@ export interface PersistOptions {
59
59
 
60
60
  /**
61
61
  * Function returning blob of data to be used for reading state.
62
- * Ignored if `prefKey`, `localStorageKey` or `dashViewModel` are provided.
62
+ * Ignored if `prefKey`, `localStorageKey`, `dashViewModel` or 'viewManagerModel' are provided.
63
63
  */
64
64
  getData?: () => any;
65
65
 
66
66
  /**
67
67
  * Function to be used to write blob of data representing state.
68
- * Ignored if `prefKey`, `localStorageKey` or `dashViewModel` are provided.
68
+ * Ignored if `prefKey`, `localStorageKey`, `dashViewModel` or 'viewManagerModel' are provided.
69
69
  */
70
70
  setData?: (data: object) => void;
71
71
  }
package/data/Store.ts CHANGED
@@ -515,10 +515,12 @@ export class Store extends HoistBase {
515
515
 
516
516
  return new StoreRecord({
517
517
  id,
518
- data: parsedData,
519
518
  store: this,
519
+ raw: null,
520
+ data: parsedData,
521
+ committedData: null,
520
522
  parent,
521
- committedData: null
523
+ isSummary: false
522
524
  });
523
525
  });
524
526
 
@@ -585,13 +587,22 @@ export class Store extends HoistBase {
585
587
  const currentRec = this.getOrThrow(id),
586
588
  updatedData = this.parseUpdate(currentRec.data, mod);
587
589
 
590
+ // If after parsing, data is deep equal, its a no-op
591
+ if (equal(updatedData, currentRec.data)) return;
592
+
593
+ // Previously updated record might now be reverted to clean, normalize
594
+ const committedData =
595
+ currentRec.isModified && equal(currentRec.committedData, updatedData)
596
+ ? updatedData
597
+ : currentRec.committedData;
598
+
588
599
  const updatedRec = new StoreRecord({
589
600
  id: currentRec.id,
601
+ store: currentRec.store,
590
602
  raw: currentRec.raw,
591
603
  data: updatedData,
604
+ committedData: committedData,
592
605
  parent: currentRec.parent,
593
- store: currentRec.store,
594
- committedData: currentRec.committedData,
595
606
  isSummary: currentRec.isSummary
596
607
  });
597
608
 
@@ -1036,7 +1047,15 @@ export class Store extends HoistBase {
1036
1047
  }
1037
1048
 
1038
1049
  data = this.parseRaw(data);
1039
- const ret = new StoreRecord({id, data, raw, parent, store: this, isSummary});
1050
+ const ret = new StoreRecord({
1051
+ id,
1052
+ store: this,
1053
+ raw,
1054
+ data,
1055
+ committedData: data,
1056
+ parent,
1057
+ isSummary
1058
+ });
1040
1059
 
1041
1060
  // Finalize summary only. Non-summary finalized by RecordSet
1042
1061
  if (isSummary) ret.finalize();
@@ -1093,7 +1112,7 @@ export class Store extends HoistBase {
1093
1112
  return ret;
1094
1113
  }
1095
1114
 
1096
- private parseUpdate(data, update) {
1115
+ private parseUpdate(data: PlainObject, update: PlainObject): PlainObject {
1097
1116
  const {_fieldMap} = this;
1098
1117
 
1099
1118
  // a) clone the existing object
@@ -1151,9 +1170,11 @@ export class Store extends HoistBase {
1151
1170
 
1152
1171
  const ret = new StoreRecord({
1153
1172
  id: recToRevert.id,
1154
- raw: recToRevert.raw,
1155
- data: {...recToRevert.committedData},
1156
1173
  store: this,
1174
+ raw: recToRevert.raw,
1175
+ data: recToRevert.committedData,
1176
+ committedData: recToRevert.committedData,
1177
+ parent: null,
1157
1178
  isSummary: true
1158
1179
  });
1159
1180
  ret.finalize();
@@ -6,11 +6,12 @@
6
6
  */
7
7
  import {PlainObject} from '@xh/hoist/core';
8
8
  import {throwIf} from '@xh/hoist/utils/js';
9
- import {isNil, flatMap, isMatch} from 'lodash';
9
+ import {isNil, flatMap, isMatch, isEmpty, pickBy} from 'lodash';
10
10
  import {Store} from './Store';
11
11
  import {ValidationState} from './validation/ValidationState';
12
12
  import {RecordValidator} from './impl/RecordValidator';
13
13
  import {Field} from './Field';
14
+ import equal from 'fast-deep-equal';
14
15
 
15
16
  /**
16
17
  * Wrapper object for each data element within a {@link Store}. Records must be assigned a unique ID
@@ -184,6 +185,26 @@ export class StoreRecord {
184
185
  return ret;
185
186
  }
186
187
 
188
+ /**
189
+ * Get a map of modified values only.
190
+ *
191
+ * If record has no modifications, this method will return null.
192
+ * If modifications are returned, the returned object will include id,
193
+ * for convenience.
194
+ */
195
+ getModifiedValues(): PlainObject {
196
+ if (!this.isModified) return null;
197
+
198
+ const {data, committedData} = this,
199
+ ret = pickBy(data, (v, k) => !equal(v, committedData[k]));
200
+ if (!isEmpty(ret)) {
201
+ ret.id = this.id;
202
+ return ret;
203
+ } else {
204
+ return null;
205
+ }
206
+ }
207
+
187
208
  /**
188
209
  * Construct a StoreRecord from a pre-processed `data` source object.
189
210
  *
@@ -195,15 +216,7 @@ export class StoreRecord {
195
216
  * @internal
196
217
  */
197
218
  constructor(config: StoreRecordConfig) {
198
- const {
199
- id,
200
- store,
201
- data,
202
- raw = null,
203
- committedData = data,
204
- parent,
205
- isSummary = false
206
- } = config;
219
+ const {id, store, raw, data, committedData, parent, isSummary} = config;
207
220
  throwIf(
208
221
  isNil(id),
209
222
  "Record needs an ID. Use 'Store.idSpec' to specify a unique ID for each record."
package/data/cube/View.ts CHANGED
@@ -373,7 +373,7 @@ export class View extends HoistBase {
373
373
  if (isNil(bucketVal)) {
374
374
  ret.push(row);
375
375
  } else {
376
- const bucketRows = buckets[bucketVal] ??= [];
376
+ const bucketRows = (buckets[bucketVal] ??= []);
377
377
  bucketRows.push(row);
378
378
  }
379
379
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "78.0.0-SNAPSHOT.1761929921002",
3
+ "version": "78.0.0-SNAPSHOT.1762216163824",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",