@arrai-innovations/reactive-helpers 4.1.2 → 4.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -103,7 +103,7 @@ export function useListCalculated({
103
103
  state.objects = toRef(parentState, "objects");
104
104
  state.objectsInOrder = toRef(parentState, "objectsInOrder");
105
105
  state[copn] = toRef(state, "calculatedObjectsObjects");
106
- for (let key in passThroughPropertyNames) {
106
+ for (let key of passThroughPropertyNames) {
107
107
  state[key] = toRef(parentState, key);
108
108
  }
109
109
 
@@ -110,7 +110,7 @@ export function useListRelated({
110
110
  state.objects = toRef(parentState, "objects");
111
111
  state.objectsInOrder = toRef(parentState, "objectsInOrder");
112
112
  state[ropn] = toRef(state, "relatedObjectsObjects");
113
- for (let key in passThroughPropertyNames) {
113
+ for (let key of passThroughPropertyNames) {
114
114
  state[key] = toRef(parentState, key);
115
115
  }
116
116
 
@@ -155,7 +155,7 @@ export function useListSubscription({
155
155
  state.objects = toRef(parentState, "objects");
156
156
  state.order = toRef(parentState, "order");
157
157
  state.objectsInOrder = toRef(parentState, "objectsInOrder");
158
- for (let key in passThroughPropertyNames) {
158
+ for (let key of passThroughPropertyNames) {
159
159
  state[key] = toRef(parentState, key);
160
160
  }
161
161
 
@@ -42,7 +42,7 @@ export function useObjectCalculated({
42
42
  state.deleted = toRef(parentState, "deleted");
43
43
  state.object = toRef(parentState, "object");
44
44
  state[copn] = toRef(state, "calculatedObjectObjects");
45
- for (let key in passThroughPropertyNames) {
45
+ for (let key of passThroughPropertyNames) {
46
46
  state[key] = toRef(parentState, key);
47
47
  }
48
48
 
@@ -41,7 +41,7 @@ export function useObjectRelated({
41
41
  state.deleted = toRef(parentState, "deleted");
42
42
  state.object = toRef(parentState, "object");
43
43
  state[ropn] = toRef(state, "relatedObjectObjects");
44
- for (let key in passThroughPropertyNames) {
44
+ for (let key of passThroughPropertyNames) {
45
45
  state[key] = toRef(parentState, key);
46
46
  }
47
47
 
@@ -116,14 +116,7 @@ export function assignReactiveObject(target, source, exclude = []) {
116
116
  addOrUpdateReactiveObject(target, source, exclude, addedKeys, sameKeys);
117
117
  }
118
118
 
119
- function assignReactiveObjectRecursive(target, source, exclude = [], path = "") {
120
- let addedKeys, sameKeys, removedKeys;
121
- try {
122
- ({ addedKeys, sameKeys, removedKeys } = keyDiff(Object.keys(source) || [], Object.keys(target) || []));
123
- } catch (error) {
124
- debugger;
125
- }
126
- trimReactiveObject(target, removedKeys, exclude);
119
+ function recursiveInner(target, source, exclude, addedKeys, sameKeys, path, fn) {
127
120
  addReactiveObject(target, source, exclude, addedKeys);
128
121
  const keysForRecurse = [];
129
122
  const keysForReplace = [];
@@ -143,10 +136,16 @@ function assignReactiveObjectRecursive(target, source, exclude = [], path = "")
143
136
  .filter((excludeKey) => !excludeKey.startsWith(path))
144
137
  .map((excludeKey) => excludeKey.replace(path, ""));
145
138
  const nextPath = isArray(source[key]) ? `${path}[${key}]` : `${path}.${key}`;
146
- assignReactiveObjectRecursive(target[key], source[key], nextLevelExclude, nextPath);
139
+ fn(target[key], source[key], nextLevelExclude, nextPath);
147
140
  }
148
141
  }
149
142
 
143
+ function assignReactiveObjectRecursive(target, source, exclude = [], path = "") {
144
+ let { addedKeys, sameKeys, removedKeys } = keyDiff(Object.keys(source) || [], Object.keys(target) || []);
145
+ trimReactiveObject(target, removedKeys, exclude);
146
+ recursiveInner(target, source, exclude, addedKeys, sameKeys, path, assignReactiveObjectRecursive);
147
+ }
148
+
150
149
  export function assignReactiveObjectDeep(target, source, exclude = []) {
151
150
  // exclude keys will need to be lodash get strings
152
151
  if (target === source) {
@@ -155,3 +154,18 @@ export function assignReactiveObjectDeep(target, source, exclude = []) {
155
154
  ({ target, source } = validateTargetAndSource(target, source));
156
155
  assignReactiveObjectRecursive(target, source, exclude);
157
156
  }
157
+
158
+ function addOrUpdateReactiveObjectRecursive(target, source, exclude = [], path = "") {
159
+ let addedKeys,
160
+ sameKeys = keyDiff(Object.keys(source) || [], Object.keys(target) || []);
161
+ recursiveInner(target, source, exclude, addedKeys, sameKeys, path, addOrUpdateReactiveObjectRecursive);
162
+ }
163
+
164
+ export function addOrUpdateReactiveObjectDeep(target, source, exclude = []) {
165
+ // exclude keys will need to be lodash get strings
166
+ if (target === source) {
167
+ return;
168
+ }
169
+ ({ target, source } = validateTargetAndSource(target, source));
170
+ addOrUpdateReactiveObjectRecursive(target, source, exclude);
171
+ }