roboto-js 1.4.26 → 1.4.28

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.
@@ -77,20 +77,25 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
77
77
  key: "set",
78
78
  value: function set(path, value) {
79
79
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
80
- var currentValue = _lodash["default"].get(this._data, path);
80
+ var currentValue = _lodash["default"].get(this._data, path); // Fetch current value at deep path
81
81
 
82
- // Check if merge is required
83
82
  if (options.merge) {
84
- // Merge the value if merge option is true
85
- var mergedValue = _lodash["default"].merge({}, currentValue, value);
83
+ var mergedValue = _lodash["default"].mergeWith({}, currentValue, value, function (objValue, srcValue) {
84
+ if (_lodash["default"].isArray(objValue)) {
85
+ return srcValue; // Customize merging behavior for arrays
86
+ }
87
+ // Handle null, 0, and "" explicitly
88
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
89
+ return srcValue;
90
+ }
91
+ });
86
92
  if (!_lodash["default"].isEqual(currentValue, mergedValue)) {
87
- _lodash["default"].set(this._data, path, mergedValue);
93
+ _lodash["default"].set(this._data, path, mergedValue); // Set the merged value at the deep path
88
94
  this._addChange(path);
89
95
  }
90
96
  } else {
91
- // Set the value directly if no merge option or merge option is false
92
97
  if (!_lodash["default"].isEqual(currentValue, value)) {
93
- _lodash["default"].set(this._data, path, value);
98
+ _lodash["default"].set(this._data, path, value); // Set the value directly at the deep path
94
99
  this._addChange(path);
95
100
  }
96
101
  }
@@ -99,16 +104,73 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
99
104
  key: "setData",
100
105
  value: function setData(newData) {
101
106
  var _this2 = this;
107
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
102
108
  if (_typeof(newData) !== 'object' || newData === null) {
103
109
  throw new Error('setData expects an object');
104
110
  }
105
- Object.keys(newData).forEach(function (key) {
106
- if (!_lodash["default"].isEqual(_lodash["default"].get(_this2._data, key), newData[key])) {
107
- _lodash["default"].set(_this2._data, key, newData[key]);
108
- _this2._addChange(key);
111
+ var _options$merge = options.merge,
112
+ merge = _options$merge === void 0 ? false : _options$merge;
113
+ Object.keys(newData).forEach(function (path) {
114
+ var currentValue = _lodash["default"].get(_this2._data, path);
115
+ var newValue = newData[path];
116
+ if (merge && _lodash["default"].isObject(currentValue) && _lodash["default"].isObject(newValue)) {
117
+ var mergedValue = _lodash["default"].mergeWith({}, currentValue, newValue, function (objValue, srcValue) {
118
+ if (_lodash["default"].isArray(objValue)) {
119
+ return srcValue; // Customize merging behavior for arrays
120
+ }
121
+ // Handle null, 0, and "" explicitly
122
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
123
+ return srcValue;
124
+ }
125
+ });
126
+ if (!_lodash["default"].isEqual(currentValue, mergedValue)) {
127
+ _lodash["default"].set(_this2._data, path, mergedValue);
128
+ _this2._addChange(path);
129
+ }
130
+ } else if (!_lodash["default"].isEqual(currentValue, newValue)) {
131
+ _lodash["default"].setWith(_this2._data, path, newValue, function (nsValue, key, nsObject, nsPath) {
132
+ if (key === nsPath.split('.').pop() && !_lodash["default"].has(nsObject, key)) {
133
+ return nsObject[key] = {}; // Create any missing parts of the path as plain objects
134
+ }
135
+ return nsValue;
136
+ });
137
+ _this2._addChange(path);
109
138
  }
110
139
  });
111
140
  }
141
+
142
+ // set(path, value, options = {}) {
143
+ // const currentValue = _.get(this._data, path);
144
+ //
145
+ // // Check if merge is required
146
+ // if (options.merge) {
147
+ // // Merge the value if merge option is true
148
+ // const mergedValue = _.merge({}, currentValue, value);
149
+ // if (!_.isEqual(currentValue, mergedValue)) {
150
+ // _.set(this._data, path, mergedValue);
151
+ // this._addChange(path);
152
+ // }
153
+ // } else {
154
+ // // Set the value directly if no merge option or merge option is false
155
+ // if (!_.isEqual(currentValue, value)) {
156
+ // _.set(this._data, path, value);
157
+ // this._addChange(path);
158
+ // }
159
+ // }
160
+ // }
161
+ //
162
+ // setData(newData) {
163
+ // if (typeof newData !== 'object' || newData === null) {
164
+ // throw new Error('setData expects an object');
165
+ // }
166
+ //
167
+ // Object.keys(newData).forEach(key => {
168
+ // if (!_.isEqual(_.get(this._data, key), newData[key])) {
169
+ // _.set(this._data, key, newData[key]);
170
+ // this._addChange(key);
171
+ // }
172
+ // });
173
+ // }
112
174
  }, {
113
175
  key: "toRecord",
114
176
  value: function toRecord() {
@@ -47,35 +47,98 @@ export default class RbtObject {
47
47
  }
48
48
  }
49
49
  set(path, value, options = {}) {
50
- const currentValue = _.get(this._data, path);
50
+ const currentValue = _.get(this._data, path); // Fetch current value at deep path
51
51
 
52
- // Check if merge is required
53
52
  if (options.merge) {
54
- // Merge the value if merge option is true
55
- const mergedValue = _.merge({}, currentValue, value);
53
+ const mergedValue = _.mergeWith({}, currentValue, value, (objValue, srcValue) => {
54
+ if (_.isArray(objValue)) {
55
+ return srcValue; // Customize merging behavior for arrays
56
+ }
57
+ // Handle null, 0, and "" explicitly
58
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
59
+ return srcValue;
60
+ }
61
+ });
56
62
  if (!_.isEqual(currentValue, mergedValue)) {
57
- _.set(this._data, path, mergedValue);
63
+ _.set(this._data, path, mergedValue); // Set the merged value at the deep path
58
64
  this._addChange(path);
59
65
  }
60
66
  } else {
61
- // Set the value directly if no merge option or merge option is false
62
67
  if (!_.isEqual(currentValue, value)) {
63
- _.set(this._data, path, value);
68
+ _.set(this._data, path, value); // Set the value directly at the deep path
64
69
  this._addChange(path);
65
70
  }
66
71
  }
67
72
  }
68
- setData(newData) {
73
+ setData(newData, options = {}) {
69
74
  if (typeof newData !== 'object' || newData === null) {
70
75
  throw new Error('setData expects an object');
71
76
  }
72
- Object.keys(newData).forEach(key => {
73
- if (!_.isEqual(_.get(this._data, key), newData[key])) {
74
- _.set(this._data, key, newData[key]);
75
- this._addChange(key);
77
+ const {
78
+ merge = false
79
+ } = options;
80
+ Object.keys(newData).forEach(path => {
81
+ const currentValue = _.get(this._data, path);
82
+ const newValue = newData[path];
83
+ if (merge && _.isObject(currentValue) && _.isObject(newValue)) {
84
+ const mergedValue = _.mergeWith({}, currentValue, newValue, (objValue, srcValue) => {
85
+ if (_.isArray(objValue)) {
86
+ return srcValue; // Customize merging behavior for arrays
87
+ }
88
+ // Handle null, 0, and "" explicitly
89
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
90
+ return srcValue;
91
+ }
92
+ });
93
+ if (!_.isEqual(currentValue, mergedValue)) {
94
+ _.set(this._data, path, mergedValue);
95
+ this._addChange(path);
96
+ }
97
+ } else if (!_.isEqual(currentValue, newValue)) {
98
+ _.setWith(this._data, path, newValue, (nsValue, key, nsObject, nsPath) => {
99
+ if (key === nsPath.split('.').pop() && !_.has(nsObject, key)) {
100
+ return nsObject[key] = {}; // Create any missing parts of the path as plain objects
101
+ }
102
+ return nsValue;
103
+ });
104
+ this._addChange(path);
76
105
  }
77
106
  });
78
107
  }
108
+
109
+ // set(path, value, options = {}) {
110
+ // const currentValue = _.get(this._data, path);
111
+ //
112
+ // // Check if merge is required
113
+ // if (options.merge) {
114
+ // // Merge the value if merge option is true
115
+ // const mergedValue = _.merge({}, currentValue, value);
116
+ // if (!_.isEqual(currentValue, mergedValue)) {
117
+ // _.set(this._data, path, mergedValue);
118
+ // this._addChange(path);
119
+ // }
120
+ // } else {
121
+ // // Set the value directly if no merge option or merge option is false
122
+ // if (!_.isEqual(currentValue, value)) {
123
+ // _.set(this._data, path, value);
124
+ // this._addChange(path);
125
+ // }
126
+ // }
127
+ // }
128
+ //
129
+ // setData(newData) {
130
+ // if (typeof newData !== 'object' || newData === null) {
131
+ // throw new Error('setData expects an object');
132
+ // }
133
+ //
134
+ // Object.keys(newData).forEach(key => {
135
+ // if (!_.isEqual(_.get(this._data, key), newData[key])) {
136
+ // _.set(this._data, key, newData[key]);
137
+ // this._addChange(key);
138
+ // }
139
+ // });
140
+ // }
141
+
79
142
  toRecord() {
80
143
  return {
81
144
  ...this._internalData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.26",
3
+ "version": "1.4.28",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_object.js CHANGED
@@ -53,38 +53,104 @@ export default class RbtObject {
53
53
  }
54
54
 
55
55
  set(path, value, options = {}) {
56
- const currentValue = _.get(this._data, path);
56
+ const currentValue = _.get(this._data, path); // Fetch current value at deep path
57
57
 
58
- // Check if merge is required
59
58
  if (options.merge) {
60
- // Merge the value if merge option is true
61
- const mergedValue = _.merge({}, currentValue, value);
62
- if (!_.isEqual(currentValue, mergedValue)) {
63
- _.set(this._data, path, mergedValue);
64
- this._addChange(path);
65
- }
59
+ const mergedValue = _.mergeWith({}, currentValue, value, (objValue, srcValue) => {
60
+ if (_.isArray(objValue)) {
61
+ return srcValue; // Customize merging behavior for arrays
62
+ }
63
+ // Handle null, 0, and "" explicitly
64
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
65
+ return srcValue;
66
+ }
67
+ });
68
+ if (!_.isEqual(currentValue, mergedValue)) {
69
+ _.set(this._data, path, mergedValue); // Set the merged value at the deep path
70
+ this._addChange(path);
71
+ }
66
72
  } else {
67
- // Set the value directly if no merge option or merge option is false
68
- if (!_.isEqual(currentValue, value)) {
69
- _.set(this._data, path, value);
70
- this._addChange(path);
71
- }
73
+ if (!_.isEqual(currentValue, value)) {
74
+ _.set(this._data, path, value); // Set the value directly at the deep path
75
+ this._addChange(path);
76
+ }
72
77
  }
73
78
  }
74
79
 
75
- setData(newData) {
76
- if (typeof newData !== 'object' || newData === null) {
77
- throw new Error('setData expects an object');
78
- }
79
-
80
- Object.keys(newData).forEach(key => {
81
- if (!_.isEqual(_.get(this._data, key), newData[key])) {
82
- _.set(this._data, key, newData[key]);
83
- this._addChange(key);
80
+ setData(newData, options = {}) {
81
+ if (typeof newData !== 'object' || newData === null) {
82
+ throw new Error('setData expects an object');
84
83
  }
85
- });
84
+
85
+ const { merge = false } = options;
86
+
87
+ Object.keys(newData).forEach(path => {
88
+ const currentValue = _.get(this._data, path);
89
+ const newValue = newData[path];
90
+
91
+ if (merge && _.isObject(currentValue) && _.isObject(newValue)) {
92
+ const mergedValue = _.mergeWith({}, currentValue, newValue, (objValue, srcValue) => {
93
+ if (_.isArray(objValue)) {
94
+ return srcValue; // Customize merging behavior for arrays
95
+ }
96
+ // Handle null, 0, and "" explicitly
97
+ if (srcValue === null || srcValue === 0 || srcValue === "") {
98
+ return srcValue;
99
+ }
100
+ });
101
+
102
+ if (!_.isEqual(currentValue, mergedValue)) {
103
+ _.set(this._data, path, mergedValue);
104
+ this._addChange(path);
105
+ }
106
+ } else if (!_.isEqual(currentValue, newValue)) {
107
+ _.setWith(this._data, path, newValue, (nsValue, key, nsObject, nsPath) => {
108
+ if (key === nsPath.split('.').pop() && !_.has(nsObject, key)) {
109
+ return nsObject[key] = {}; // Create any missing parts of the path as plain objects
110
+ }
111
+ return nsValue;
112
+ });
113
+ this._addChange(path);
114
+ }
115
+ });
86
116
  }
87
117
 
118
+
119
+
120
+
121
+ // set(path, value, options = {}) {
122
+ // const currentValue = _.get(this._data, path);
123
+ //
124
+ // // Check if merge is required
125
+ // if (options.merge) {
126
+ // // Merge the value if merge option is true
127
+ // const mergedValue = _.merge({}, currentValue, value);
128
+ // if (!_.isEqual(currentValue, mergedValue)) {
129
+ // _.set(this._data, path, mergedValue);
130
+ // this._addChange(path);
131
+ // }
132
+ // } else {
133
+ // // Set the value directly if no merge option or merge option is false
134
+ // if (!_.isEqual(currentValue, value)) {
135
+ // _.set(this._data, path, value);
136
+ // this._addChange(path);
137
+ // }
138
+ // }
139
+ // }
140
+ //
141
+ // setData(newData) {
142
+ // if (typeof newData !== 'object' || newData === null) {
143
+ // throw new Error('setData expects an object');
144
+ // }
145
+ //
146
+ // Object.keys(newData).forEach(key => {
147
+ // if (!_.isEqual(_.get(this._data, key), newData[key])) {
148
+ // _.set(this._data, key, newData[key]);
149
+ // this._addChange(key);
150
+ // }
151
+ // });
152
+ // }
153
+
88
154
  toRecord() {
89
155
  return {
90
156
  ...this._internalData,