Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobx-state-tree

Package Overview
Dependencies
Maintainers
2
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-state-tree - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

lib/types/property-types/view-property.d.ts

31

changelog.md

@@ -0,1 +1,32 @@

# 0.4.0
**BREAKING** `types.model` no requires 2 parameters to define a model. The first parameter defines the properties, derived values and view functions. The second argment is used to define the actions. For example:
```javascript
const Todo = types.model("Todo", {
done: types.boolean,
toggle() {
this.done = !this.done
}
})
```
Now should be defined as:
```javascript
const Todo = types.model(
"Todo",
{
done: types.boolean,
},
{
toggle() {
this.done = !this.done
}
}
)
```
It is still possible to define functions on the first object. However, those functions are not considered to be actions, but views. They are not allowed to modify values, but instead should produce a new value themselves.
# 0.3.3

@@ -2,0 +33,0 @@

2

lib/core/json-patch.js

@@ -0,4 +1,4 @@

"use strict";
// https://tools.ietf.org/html/rfc6902
// http://jsonpatch.com/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -5,0 +5,0 @@ /**

@@ -1,2 +0,2 @@

import { IObjectChange, IObjectWillChange, IAction } from "mobx";
import { IObjectChange, IObjectWillChange } from "mobx";
import { MSTAdministration, IMSTNode, IJsonPatch } from "../../core";

@@ -11,2 +11,3 @@ import { IType, IComplexType } from "../type";

baseModel: any;
baseActions: any;
modelConstructor: new () => any;

@@ -18,3 +19,3 @@ /**

identifierAttribute: string | null;
constructor(name: string, baseModel: Object);
constructor(name: string, baseModel: Object, baseActions: Object);
createNewInstance(): Object;

@@ -38,3 +39,3 @@ finalizeNewInstance(instance: IMSTNode, snapshot: any): void;

export declare type IBaseModelDefinition<T> = {
[K in keyof T]: IType<any, T[K]> | T[K] & IAction | T[K];
[K in keyof T]: IType<any, T[K]> | T[K];
};

@@ -44,13 +45,13 @@ export declare type Snapshot<T> = {

};
export interface IModelType<T> extends IComplexType<Snapshot<T>, T> {
export interface IModelType<T, A> extends IComplexType<Snapshot<T>, T & A> {
}
export declare function createModelFactory<T>(baseModel: IBaseModelDefinition<T>): IModelType<T>;
export declare function createModelFactory<T>(name: string, baseModel: IBaseModelDefinition<T>): IModelType<T>;
export declare function extend<A, B>(name: string, a: IModelType<A>, b: IModelType<B>): IModelType<A & B>;
export declare function extend<A, B, C>(name: string, a: IModelType<A>, b: IModelType<B>, c: IModelType<C>): IModelType<A & B & C>;
export declare function extend<A, B, C, D>(name: string, a: IModelType<A>, b: IModelType<B>, c: IModelType<C>, d: IModelType<D>): IModelType<A & B & C & D>;
export declare function extend<A, B>(a: IModelType<A>, b: IModelType<B>): IModelType<A & B>;
export declare function extend<A, B, C>(a: IModelType<A>, b: IModelType<B>, c: IModelType<C>): IModelType<A & B & C>;
export declare function extend<A, B, C, D>(a: IModelType<A>, b: IModelType<B>, c: IModelType<C>, d: IModelType<D>): IModelType<A & B & C & D>;
export declare function createModelFactory<T>(baseModel: IBaseModelDefinition<T> & ThisType<T>): IModelType<T, {}>;
export declare function createModelFactory<T>(name: string, baseModel: IBaseModelDefinition<T> & ThisType<T>): IModelType<T, {}>;
export declare function createModelFactory<T, A>(baseModel: IBaseModelDefinition<T> & ThisType<T>, actions: A & ThisType<T & A>): IModelType<T, A>;
export declare function createModelFactory<T, A>(name: string, baseModel: IBaseModelDefinition<T> & ThisType<T>, actions: A & ThisType<T & A>): IModelType<T, A>;
export declare function extend<A, B, AA, BA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>): IModelType<A & B, AA & BA>;
export declare function extend<A, B, C, AA, BA, CA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>, c: IModelType<C, CA>): IModelType<A & B & C, AA & BA & CA>;
export declare function extend<A, B, AA, BA>(a: IModelType<A, AA>, b: IModelType<B, BA>): IModelType<A & B, AA & BA>;
export declare function extend<A, B, C, AA, BA, CA>(a: IModelType<A, AA>, b: IModelType<B, BA>, c: IModelType<C, CA>): IModelType<A & B & C, AA & BA & CA>;
export declare function isObjectFactory(type: any): boolean;
export declare function getIdentifierAttribute(factory: any): string | null;

@@ -33,5 +33,6 @@ "use strict";

var action_property_1 = require("../property-types/action-property");
var view_property_1 = require("../property-types/view-property");
var ObjectType = (function (_super) {
__extends(ObjectType, _super);
function ObjectType(name, baseModel) {
function ObjectType(name, baseModel, baseActions) {
var _this = _super.call(this, name) || this;

@@ -48,3 +49,5 @@ _this.isObjectFactory = true;

Object.freeze(baseModel); // make sure nobody messes with it
Object.freeze(baseActions);
_this.baseModel = baseModel;
_this.baseActions = baseActions;
utils_1.invariant(/^\w[\w\d_]*$/.test(name), "Typename should be a valid identifier: " + name);

@@ -76,5 +79,6 @@ _this.modelConstructor = new Function("return function " + name + " (){}")(); // fancy trick to get a named function...., http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript

ObjectType.prototype.parseModelProps = function () {
var baseModel = this.baseModel;
var _a = this, baseModel = _a.baseModel, baseActions = _a.baseActions;
for (var key in baseModel)
if (utils_1.hasOwnProperty(baseModel, key)) {
// TODO: check that hooks are not defined as part of baseModel
var descriptor = Object.getOwnPropertyDescriptor(baseModel, key);

@@ -105,3 +109,3 @@ if ("get" in descriptor) {

else if (typeof value === "function") {
this.props[key] = new action_property_1.ActionProperty(key, value);
this.props[key] = new view_property_1.ViewProperty(key, value);
}

@@ -115,2 +119,14 @@ else if (typeof value === "object") {

}
for (var key in baseActions)
if (utils_1.hasOwnProperty(baseActions, key)) {
var value = baseActions[key];
if (key in this.baseModel)
utils_1.fail("Property '" + key + "' was also defined as action. Actions and properties should not collide");
if (typeof value === "function") {
this.props[key] = new action_property_1.ActionProperty(key, value);
}
else {
utils_1.fail("Unexpected value for action '" + key + "'. Expected function, got " + typeof value);
}
}
};

@@ -188,6 +204,7 @@ ObjectType.prototype.getChildMSTs = function (node) {

exports.ObjectType = ObjectType;
function createModelFactory(arg1, arg2) {
function createModelFactory(arg1, arg2, arg3) {
var name = typeof arg1 === "string" ? arg1 : "AnonymousModel";
var baseModel = typeof arg1 === "string" ? arg2 : arg1;
return new ObjectType(name, baseModel);
var actions = typeof arg1 === "string" ? arg3 : arg2;
return new ObjectType(name, baseModel, actions || {});
}

@@ -204,2 +221,3 @@ exports.createModelFactory = createModelFactory;

}
console.warn("[mobx-state-tree] `extend` is an experimental feature and it's behavior will probably change in the future");
var baseFactories = typeof args[0] === "string" ? args.slice(1) : args;

@@ -206,0 +224,0 @@ var factoryName = typeof args[0] === "string" ? args[0] : baseFactories.map(function (f) { return f.name; }).join("_");

@@ -1,2 +0,2 @@

import { IObservableArray, IAction } from "mobx";
import { IObservableArray } from "mobx";
import { IType, ISimpleType } from "./type";

@@ -8,15 +8,19 @@ import { IExtendedObservableMap } from "./complex-types/map";

<T>(baseModel: {
[K in keyof T]: T[K] | IType<any, T[K]> | (T[K] & IAction);
}): IModelType<T>;
[K in keyof T]: T[K] | IType<any, T[K]>;
} & ThisType<T>): IModelType<T, {}>;
<T>(name: string, baseModel: {
[K in keyof T]: T[K] | IType<any, T[K]> | (T[K] & IAction);
}): IModelType<T>;
[K in keyof T]: T[K] | IType<any, T[K]>;
} & ThisType<T>): IModelType<T, {}>;
<T, A>(baseModel: {
[K in keyof T]: T[K] | IType<any, T[K]>;
} & ThisType<T>, actions: A & ThisType<T & A>): IModelType<T, A>;
<T, A>(name: string, baseModel: {
[K in keyof T]: T[K] | IType<any, T[K]>;
} & ThisType<T>, actions: A & ThisType<T & A>): IModelType<T, A>;
};
extend: {
<A, B>(name: string, a: IModelType<A>, b: IModelType<B>): IModelType<A & B>;
<A, B, C>(name: string, a: IModelType<A>, b: IModelType<B>, c: IModelType<C>): IModelType<A & B & C>;
<A, B, C, D>(name: string, a: IModelType<A>, b: IModelType<B>, c: IModelType<C>, d: IModelType<D>): IModelType<A & B & C & D>;
<A, B>(a: IModelType<A>, b: IModelType<B>): IModelType<A & B>;
<A, B, C>(a: IModelType<A>, b: IModelType<B>, c: IModelType<C>): IModelType<A & B & C>;
<A, B, C, D>(a: IModelType<A>, b: IModelType<B>, c: IModelType<C>, d: IModelType<D>): IModelType<A & B & C & D>;
<A, B, AA, BA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>): IModelType<A & B, AA & BA>;
<A, B, C, AA, BA, CA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>, c: IModelType<C, CA>): IModelType<A & B & C, AA & BA & CA>;
<A, B, AA, BA>(a: IModelType<A, AA>, b: IModelType<B, BA>): IModelType<A & B, AA & BA>;
<A, B, C, AA, BA, CA>(a: IModelType<A, AA>, b: IModelType<B, BA>, c: IModelType<C, CA>): IModelType<A & B & C, AA & BA & CA>;
};

@@ -23,0 +27,0 @@ reference: {

{
"name": "mobx-state-tree",
"version": "0.3.3",
"version": "0.4.0",
"description": "Opinionated, transactional, MobX powered state container",

@@ -42,3 +42,3 @@ "main": "lib/index.js",

"tslint": "^3.15.1",
"typescript": "2.2.2",
"typescript": "next",
"webpack": "^1.13.1",

@@ -45,0 +45,0 @@ "webpack-fail-plugin": "^1.0.6"

@@ -80,8 +80,8 @@ # mobx-state-tree

// computed prop
// computed prop / views
get width() {
return this.name.length * 15
},
// action
}
}, {
// actions
move(dx, dy) {

@@ -95,3 +95,4 @@ this.x += dx

boxes: types.map(Box),
selection: types.reference("boxes/name"),
selection: types.reference("boxes/name")
}, {
addBox(name, x, y) {

@@ -163,2 +164,10 @@ const box = Box.create({ id: uuid(), name, x, y })

## Views
TODO
Views versus actions
Exception: `"Invariant failed: Side effects like changing state are not allowed at this point."` indicates that a view function tries to modifies a model. This is only allowed in actions.
## Protecting the state tree

@@ -173,3 +182,4 @@

const Todo = types.model({
done: false,
done: false
}, {
toggle() {

@@ -317,3 +327,3 @@ this.done = !this.done

[lib/core/mst-node.js:28-40](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-node.js#L28-L40 "Source code on GitHub")
[lib/core/mst-node.js:28-40](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-node.js#L28-L40 "Source code on GitHub")

@@ -332,3 +342,3 @@ Tries to convert a value to a TreeNode. If possible or already done,

[lib/types/complex-types/complex-type.js:18-50](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/types/complex-types/complex-type.js#L18-L50 "Source code on GitHub")
[lib/types/complex-types/complex-type.js:18-50](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/types/complex-types/complex-type.js#L18-L50 "Source code on GitHub")

@@ -339,3 +349,3 @@ A complex type produces a MST node (Node in the state tree)

[lib/core/mst-node-administration.js:51-55](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-node-administration.js#L51-L55 "Source code on GitHub")
[lib/core/mst-node-administration.js:51-55](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-node-administration.js#L51-L55 "Source code on GitHub")

@@ -346,3 +356,3 @@ Returnes (escaped) path representation as string

[lib/types/index.js:24-26](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/types/index.js#L24-L26 "Source code on GitHub")
[lib/types/index.js:24-26](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/types/index.js#L24-L26 "Source code on GitHub")

@@ -355,3 +365,3 @@ **Parameters**

[lib/types/index.js:34-36](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/types/index.js#L34-L36 "Source code on GitHub")
[lib/types/index.js:34-36](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/types/index.js#L34-L36 "Source code on GitHub")

@@ -364,3 +374,3 @@ **Parameters**

[lib/types/complex-types/object.js:41-41](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/types/complex-types/object.js#L41-L41 "Source code on GitHub")
[lib/types/complex-types/object.js:42-42](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/types/complex-types/object.js#L42-L42 "Source code on GitHub")

@@ -371,3 +381,3 @@ Parsed description of all properties

[lib/core/mst-operations.js:50-55](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L50-L55 "Source code on GitHub")
[lib/core/mst-operations.js:50-55](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L50-L55 "Source code on GitHub")

@@ -416,3 +426,3 @@ TODO: update docs

[lib/core/mst-operations.js:67-69](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L67-L69 "Source code on GitHub")
[lib/core/mst-operations.js:67-69](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L67-L69 "Source code on GitHub")

@@ -432,3 +442,3 @@ Registers a function that will be invoked for each that as made to the provided model instance, or any of it's children.

[lib/core/mst-operations.js:83-85](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L83-L85 "Source code on GitHub")
[lib/core/mst-operations.js:83-85](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L83-L85 "Source code on GitHub")

@@ -444,3 +454,3 @@ Applies a JSON-patch to the given model instance or bails out if the patch couldn't be applied

[lib/core/mst-operations.js:94-99](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L94-L99 "Source code on GitHub")
[lib/core/mst-operations.js:94-99](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L94-L99 "Source code on GitHub")

@@ -456,3 +466,3 @@ Applies a number of JSON patches in a single MobX transaction

[lib/core/mst-operations.js:125-129](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L125-L129 "Source code on GitHub")
[lib/core/mst-operations.js:125-129](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L125-L129 "Source code on GitHub")

@@ -471,3 +481,3 @@ Applies a series of actions in a single MobX transaction.

[lib/core/mst-operations.js:163-165](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L163-L165 "Source code on GitHub")
[lib/core/mst-operations.js:163-165](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L163-L165 "Source code on GitHub")

@@ -502,3 +512,3 @@ By default it is allowed to both directly modify a model or through an action.

[lib/core/mst-operations.js:170-172](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L170-L172 "Source code on GitHub")
[lib/core/mst-operations.js:170-172](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L170-L172 "Source code on GitHub")

@@ -513,3 +523,3 @@ Returns true if the object is in protected mode, @see protect

[lib/core/mst-operations.js:182-184](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L182-L184 "Source code on GitHub")
[lib/core/mst-operations.js:182-184](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L182-L184 "Source code on GitHub")

@@ -525,3 +535,3 @@ Applies a snapshot to a given model instances. Patch and snapshot listeners will be invoked as usual.

[lib/core/mst-operations.js:198-208](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L198-L208 "Source code on GitHub")
[lib/core/mst-operations.js:198-208](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L198-L208 "Source code on GitHub")

@@ -539,3 +549,3 @@ Given a model instance, returns `true` if the object has a parent, that is, is part of another object, map or array

[lib/core/mst-operations.js:234-236](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L234-L236 "Source code on GitHub")
[lib/core/mst-operations.js:234-236](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L234-L236 "Source code on GitHub")

@@ -552,3 +562,3 @@ Returns the path of the given object in the model tree

[lib/core/mst-operations.js:245-247](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L245-L247 "Source code on GitHub")
[lib/core/mst-operations.js:245-247](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L245-L247 "Source code on GitHub")

@@ -565,3 +575,3 @@ Returns the path of the given object as unescaped string array

[lib/core/mst-operations.js:256-258](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L256-L258 "Source code on GitHub")
[lib/core/mst-operations.js:256-258](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L256-L258 "Source code on GitHub")

@@ -578,3 +588,3 @@ Returns true if the given object is the root of a model tree

[lib/core/mst-operations.js:268-272](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L268-L272 "Source code on GitHub")
[lib/core/mst-operations.js:268-272](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L268-L272 "Source code on GitHub")

@@ -592,3 +602,3 @@ Resolves a path relatively to a given object.

[lib/core/mst-operations.js:282-287](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L282-L287 "Source code on GitHub")
[lib/core/mst-operations.js:282-287](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L282-L287 "Source code on GitHub")

@@ -604,3 +614,3 @@ **Parameters**

[lib/core/mst-operations.js:301-310](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L301-L310 "Source code on GitHub")
[lib/core/mst-operations.js:301-310](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L301-L310 "Source code on GitHub")

@@ -616,3 +626,3 @@ **Parameters**

[lib/core/mst-operations.js:315-318](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L315-L318 "Source code on GitHub")
[lib/core/mst-operations.js:315-318](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L315-L318 "Source code on GitHub")

@@ -627,3 +637,3 @@ Removes a model element from the state tree, and let it live on as a new state tree

[lib/core/mst-operations.js:323-329](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/mst-operations.js#L323-L329 "Source code on GitHub")
[lib/core/mst-operations.js:323-329](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/mst-operations.js#L323-L329 "Source code on GitHub")

@@ -638,3 +648,3 @@ Removes a model element from the state tree, and mark it as end-of-life; the element should not be used anymore

[lib/core/action.js:107-114](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/action.js#L107-L114 "Source code on GitHub")
[lib/core/action.js:107-114](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/action.js#L107-L114 "Source code on GitHub")

@@ -652,3 +662,3 @@ Dispatches an Action on a model instance. All middlewares will be triggered.

[lib/core/json-patch.js:9-11](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/json-patch.js#L9-L11 "Source code on GitHub")
[lib/core/json-patch.js:9-11](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/json-patch.js#L9-L11 "Source code on GitHub")

@@ -664,3 +674,3 @@ escape slashes and backslashes

[lib/core/json-patch.js:16-18](https://github.com/mweststrate/mobx-state-tree/blob/5b0f27f3e1deaceb2dce1246995518c4917f46a7/lib/core/json-patch.js#L16-L18 "Source code on GitHub")
[lib/core/json-patch.js:16-18](https://github.com/mweststrate/mobx-state-tree/blob/5fed6103994a6cf505e69651c17a064fb2b6d697/lib/core/json-patch.js#L16-L18 "Source code on GitHub")

@@ -716,4 +726,7 @@ unescape slashes and backslashes

TypeScript support is best effort, as not all patterns can be expressed in TypeScript. But except for assigning snapshots to properties we got pretty close! As MST uses the latest fancy typescript features it is recommended to use TypeScript 2.3 or higher, with `noImplicitThis` and `strictNullChecks` enabled.
When using models, you write interface along with it's property types that will be used to perform type checks at runtime.
What about compile time? You can use TypeScript interfaces indeed to perform those checks, but that would require writing again all the properties and their actions!
Good news? You don't need to write it twice! Using the `typeof` operator of TypeScript over the `.Type` property of a MST Type, will result in a valid TypeScript Type!

@@ -723,3 +736,4 @@

const Todo = types.model({
title: types.string,
title: types.string
}, {
setTitle(v: string) {

@@ -726,0 +740,0 @@ this.title = v

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc