roboto-js 1.4.14 → 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.
- package/dist/cjs/rbt_object.cjs +39 -11
- package/dist/esm/rbt_object.js +28 -5
- package/package.json +1 -1
- package/src/rbt_object.js +27 -5
package/dist/cjs/rbt_object.cjs
CHANGED
|
@@ -45,7 +45,25 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
45
45
|
}, {
|
|
46
46
|
key: "getData",
|
|
47
47
|
value: function getData() {
|
|
48
|
-
|
|
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
|
|
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(
|
|
89
|
-
_lodash["default"].set(
|
|
90
|
-
|
|
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
|
}
|
|
@@ -119,7 +137,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
119
137
|
key: "save",
|
|
120
138
|
value: function () {
|
|
121
139
|
var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
122
|
-
var record, response;
|
|
140
|
+
var _response$data, _response$data2, record, response;
|
|
123
141
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
124
142
|
while (1) switch (_context.prev = _context.next) {
|
|
125
143
|
case 0:
|
|
@@ -141,24 +159,34 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
141
159
|
}
|
|
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')) {
|
|
163
|
+
_context.next = 12;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
this.rpcMeta.isNew = false;
|
|
167
|
+
return _context.abrupt("return", this);
|
|
168
|
+
case 12:
|
|
169
|
+
if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
|
|
170
|
+
// apply new incoming data
|
|
171
|
+
this.setData(response.newData);
|
|
172
|
+
}
|
|
145
173
|
this.id = response.data.id;
|
|
146
174
|
this.id_revision = response.data.id_revision;
|
|
147
175
|
this.type = response.data.type;
|
|
148
176
|
this.rpcMeta.isNew = false;
|
|
149
177
|
return _context.abrupt("return", this);
|
|
150
|
-
case
|
|
151
|
-
_context.prev =
|
|
178
|
+
case 20:
|
|
179
|
+
_context.prev = 20;
|
|
152
180
|
_context.t0 = _context["catch"](2);
|
|
153
181
|
console.log('RbtObject.save.error:', _context.t0);
|
|
154
182
|
this._error = _context.t0;
|
|
155
183
|
//console.log(e.response.data);
|
|
156
184
|
throw _context.t0;
|
|
157
|
-
case
|
|
185
|
+
case 25:
|
|
158
186
|
case "end":
|
|
159
187
|
return _context.stop();
|
|
160
188
|
}
|
|
161
|
-
}, _callee, this, [[2,
|
|
189
|
+
}, _callee, this, [[2, 20]]);
|
|
162
190
|
}));
|
|
163
191
|
function save() {
|
|
164
192
|
return _save.apply(this, arguments);
|
package/dist/esm/rbt_object.js
CHANGED
|
@@ -19,10 +19,26 @@ export default class RbtObject {
|
|
|
19
19
|
get(path) {
|
|
20
20
|
return _.get(this._data, path);
|
|
21
21
|
}
|
|
22
|
-
getData() {
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
@@ -91,7 +107,14 @@ export default class RbtObject {
|
|
|
91
107
|
if (response.data.ok === false) {
|
|
92
108
|
throw new Error(response.data.message);
|
|
93
109
|
}
|
|
94
|
-
|
|
110
|
+
if (response.data?.result == 'NO_CHANGES') {
|
|
111
|
+
this.rpcMeta.isNew = false;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
if (response.data?.newData) {
|
|
115
|
+
// apply new incoming data
|
|
116
|
+
this.setData(response.newData);
|
|
117
|
+
}
|
|
95
118
|
this.id = response.data.id;
|
|
96
119
|
this.id_revision = response.data.id_revision;
|
|
97
120
|
this.type = response.data.type;
|
package/package.json
CHANGED
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
|
-
|
|
30
|
-
|
|
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) {
|
|
@@ -106,7 +120,15 @@ export default class RbtObject {
|
|
|
106
120
|
throw new Error(response.data.message);
|
|
107
121
|
}
|
|
108
122
|
|
|
109
|
-
|
|
123
|
+
if(response.data?.result == 'NO_CHANGES'){
|
|
124
|
+
this.rpcMeta.isNew = false;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if(response.data?.newData){
|
|
129
|
+
// apply new incoming data
|
|
130
|
+
this.setData(response.newData);
|
|
131
|
+
}
|
|
110
132
|
|
|
111
133
|
this.id = response.data.id;
|
|
112
134
|
this.id_revision = response.data.id_revision;
|