roboto-js 1.4.15 → 1.4.16

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.
@@ -45,7 +45,25 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
45
45
  }, {
46
46
  key: "getData",
47
47
  value: function getData() {
48
- return _objectSpread({}, this._data);
48
+ var _this = this;
49
+ var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
50
+ // Check if keys are provided
51
+ if (keys && Array.isArray(keys)) {
52
+ // Return an object with only the specified keys
53
+ return keys.reduce(function (result, key) {
54
+ // Use lodash.get to handle deep key paths
55
+ var value = _lodash["default"].get(_this._data, key);
56
+ // If the value exists, add it to the result object using the key path as the property name
57
+ if (value !== undefined) {
58
+ // Create nested structure based on the key path
59
+ _lodash["default"].set(result, key, value);
60
+ }
61
+ return result;
62
+ }, {});
63
+ } else {
64
+ // Return a shallow copy of the full data if no keys are provided
65
+ return _objectSpread({}, this._data);
66
+ }
49
67
  }
50
68
  }, {
51
69
  key: "_addChange",
@@ -80,14 +98,14 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
80
98
  }, {
81
99
  key: "setData",
82
100
  value: function setData(newData) {
83
- var _this = this;
101
+ var _this2 = this;
84
102
  if (_typeof(newData) !== 'object' || newData === null) {
85
103
  throw new Error('setData expects an object');
86
104
  }
87
105
  Object.keys(newData).forEach(function (key) {
88
- if (!_lodash["default"].isEqual(_lodash["default"].get(_this._data, key), newData[key])) {
89
- _lodash["default"].set(_this._data, key, newData[key]);
90
- _this._addChange(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);
91
109
  }
92
110
  });
93
111
  }
@@ -142,11 +160,12 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
142
160
  throw new Error(response.data.message);
143
161
  case 9:
144
162
  if (!(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.result) == 'NO_CHANGES')) {
145
- _context.next = 11;
163
+ _context.next = 12;
146
164
  break;
147
165
  }
166
+ this.rpcMeta.isNew = false;
148
167
  return _context.abrupt("return", this);
149
- case 11:
168
+ case 12:
150
169
  if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
151
170
  // apply new incoming data
152
171
  this.setData(response.newData);
@@ -156,18 +175,18 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
156
175
  this.type = response.data.type;
157
176
  this.rpcMeta.isNew = false;
158
177
  return _context.abrupt("return", this);
159
- case 19:
160
- _context.prev = 19;
178
+ case 20:
179
+ _context.prev = 20;
161
180
  _context.t0 = _context["catch"](2);
162
181
  console.log('RbtObject.save.error:', _context.t0);
163
182
  this._error = _context.t0;
164
183
  //console.log(e.response.data);
165
184
  throw _context.t0;
166
- case 24:
185
+ case 25:
167
186
  case "end":
168
187
  return _context.stop();
169
188
  }
170
- }, _callee, this, [[2, 19]]);
189
+ }, _callee, this, [[2, 20]]);
171
190
  }));
172
191
  function save() {
173
192
  return _save.apply(this, arguments);
@@ -19,10 +19,26 @@ export default class RbtObject {
19
19
  get(path) {
20
20
  return _.get(this._data, path);
21
21
  }
22
- getData() {
23
- return {
24
- ...this._data
25
- };
22
+ getData(keys = null) {
23
+ // Check if keys are provided
24
+ if (keys && Array.isArray(keys)) {
25
+ // Return an object with only the specified keys
26
+ return keys.reduce((result, key) => {
27
+ // Use lodash.get to handle deep key paths
28
+ const value = _.get(this._data, key);
29
+ // If the value exists, add it to the result object using the key path as the property name
30
+ if (value !== undefined) {
31
+ // Create nested structure based on the key path
32
+ _.set(result, key, value);
33
+ }
34
+ return result;
35
+ }, {});
36
+ } else {
37
+ // Return a shallow copy of the full data if no keys are provided
38
+ return {
39
+ ...this._data
40
+ };
41
+ }
26
42
  }
27
43
  _addChange(path) {
28
44
  // Ensure no duplicate paths
@@ -92,6 +108,7 @@ export default class RbtObject {
92
108
  throw new Error(response.data.message);
93
109
  }
94
110
  if (response.data?.result == 'NO_CHANGES') {
111
+ this.rpcMeta.isNew = false;
95
112
  return this;
96
113
  }
97
114
  if (response.data?.newData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.15",
3
+ "version": "1.4.16",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_object.js CHANGED
@@ -25,10 +25,24 @@ export default class RbtObject {
25
25
  return _.get(this._data, path);
26
26
  }
27
27
 
28
- getData() {
29
- return {
30
- ...this._data
31
- };
28
+ getData(keys = null) {
29
+ // Check if keys are provided
30
+ if (keys && Array.isArray(keys)) {
31
+ // Return an object with only the specified keys
32
+ return keys.reduce((result, key) => {
33
+ // Use lodash.get to handle deep key paths
34
+ const value = _.get(this._data, key);
35
+ // If the value exists, add it to the result object using the key path as the property name
36
+ if (value !== undefined) {
37
+ // Create nested structure based on the key path
38
+ _.set(result, key, value);
39
+ }
40
+ return result;
41
+ }, {});
42
+ } else {
43
+ // Return a shallow copy of the full data if no keys are provided
44
+ return { ...this._data };
45
+ }
32
46
  }
33
47
 
34
48
  _addChange(path) {
@@ -107,6 +121,7 @@ export default class RbtObject {
107
121
  }
108
122
 
109
123
  if(response.data?.result == 'NO_CHANGES'){
124
+ this.rpcMeta.isNew = false;
110
125
  return this;
111
126
  }
112
127