mobx-state-tree 7.0.0-pre.2 → 7.0.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/dist/mobx-state-tree.js +31 -19
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +31 -19
- package/dist/mobx-state-tree.umd.js +31 -19
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/complex-types/model.d.ts +10 -7
- package/dist/types/utility-types/union.d.ts +13 -4
- package/package.json +4 -4
package/dist/mobx-state-tree.js
CHANGED
|
@@ -6129,11 +6129,16 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6129
6129
|
configurable: true,
|
|
6130
6130
|
writable: true,
|
|
6131
6131
|
value: function (self, actions) {
|
|
6132
|
+
var _this = this;
|
|
6132
6133
|
// check if return is correct
|
|
6133
|
-
if (!isPlainObject(actions))
|
|
6134
|
+
if (!isPlainObject(actions)) {
|
|
6134
6135
|
throw new MstError("actions initializer should return a plain object containing actions");
|
|
6136
|
+
}
|
|
6135
6137
|
// bind actions to the object created
|
|
6136
|
-
Object.
|
|
6138
|
+
Object.getOwnPropertyNames(actions).forEach(function (name) {
|
|
6139
|
+
if (name in _this.properties) {
|
|
6140
|
+
throw new MstError("'".concat(name, "' is a property and cannot be declared as an action"));
|
|
6141
|
+
}
|
|
6137
6142
|
// warn if preprocessor was given
|
|
6138
6143
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6139
6144
|
throw new MstError("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
|
|
@@ -6183,10 +6188,17 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6183
6188
|
configurable: true,
|
|
6184
6189
|
writable: true,
|
|
6185
6190
|
value: function (self, state) {
|
|
6191
|
+
var _this = this;
|
|
6186
6192
|
// check views return
|
|
6187
|
-
if (!isPlainObject(state))
|
|
6193
|
+
if (!isPlainObject(state)) {
|
|
6188
6194
|
throw new MstError("volatile state initializer should return a plain object containing state");
|
|
6189
|
-
|
|
6195
|
+
}
|
|
6196
|
+
Object.getOwnPropertyNames(state).forEach(function (name) {
|
|
6197
|
+
if (name in _this.properties) {
|
|
6198
|
+
throw new MstError("'".concat(name, "' is a property and cannot be declared as volatile state"));
|
|
6199
|
+
}
|
|
6200
|
+
mobx.set(self, name, state[name]);
|
|
6201
|
+
});
|
|
6190
6202
|
}
|
|
6191
6203
|
});
|
|
6192
6204
|
Object.defineProperty(ModelType.prototype, "extend", {
|
|
@@ -6228,19 +6240,24 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6228
6240
|
configurable: true,
|
|
6229
6241
|
writable: true,
|
|
6230
6242
|
value: function (self, views) {
|
|
6243
|
+
var _this = this;
|
|
6231
6244
|
// check views return
|
|
6232
|
-
if (!isPlainObject(views))
|
|
6245
|
+
if (!isPlainObject(views)) {
|
|
6233
6246
|
throw new MstError("views initializer should return a plain object containing views");
|
|
6234
|
-
|
|
6247
|
+
}
|
|
6248
|
+
Object.getOwnPropertyNames(views).forEach(function (name) {
|
|
6235
6249
|
var _a;
|
|
6250
|
+
if (name in _this.properties) {
|
|
6251
|
+
throw new MstError("'".concat(name, "' is a property and cannot be declared as a view"));
|
|
6252
|
+
}
|
|
6236
6253
|
// is this a computed property?
|
|
6237
|
-
var descriptor = Object.getOwnPropertyDescriptor(views,
|
|
6254
|
+
var descriptor = Object.getOwnPropertyDescriptor(views, name);
|
|
6238
6255
|
if ("get" in descriptor) {
|
|
6239
|
-
mobx.defineProperty(self,
|
|
6240
|
-
mobx.makeObservable(self, (_a = {}, _a[
|
|
6256
|
+
mobx.defineProperty(self, name, descriptor);
|
|
6257
|
+
mobx.makeObservable(self, (_a = {}, _a[name] = mobx.computed, _a));
|
|
6241
6258
|
}
|
|
6242
6259
|
else if (typeof descriptor.value === "function") {
|
|
6243
|
-
(!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self,
|
|
6260
|
+
(!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, name, descriptor.value);
|
|
6244
6261
|
}
|
|
6245
6262
|
else {
|
|
6246
6263
|
throw new MstError("A view member should either be a function or getter based property");
|
|
@@ -6376,14 +6393,9 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6376
6393
|
if (applyPostProcess === void 0) { applyPostProcess = true; }
|
|
6377
6394
|
var res = {};
|
|
6378
6395
|
this.forAllProps(function (name, type) {
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
atom.reportObserved();
|
|
6383
|
-
}
|
|
6384
|
-
catch (e) {
|
|
6385
|
-
throw new MstError("".concat(name, " property is declared twice"));
|
|
6386
|
-
}
|
|
6396
|
+
// TODO: FIXME, make sure the observable ref is used!
|
|
6397
|
+
var atom = mobx.getAtom(node.storedValue, name);
|
|
6398
|
+
atom.reportObserved();
|
|
6387
6399
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6388
6400
|
});
|
|
6389
6401
|
if (applyPostProcess) {
|
|
@@ -7177,7 +7189,7 @@ function union(optionsOrType) {
|
|
|
7177
7189
|
otherTypes[_i - 1] = arguments[_i];
|
|
7178
7190
|
}
|
|
7179
7191
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7180
|
-
var types = isType(optionsOrType) ? __spreadArray([optionsOrType], __read(otherTypes), false) : otherTypes;
|
|
7192
|
+
var types = (isType(optionsOrType) ? __spreadArray([optionsOrType], __read(otherTypes), false) : otherTypes);
|
|
7181
7193
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7182
7194
|
// check all options
|
|
7183
7195
|
if (devMode()) {
|