mobx-decorated-models
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -27,8 +27,8 @@ (function (global, factory) { | ||
function defaultModelLookup({ property, model = property }) { | ||
if (typeof model === 'function') { | ||
const defaultModelLookup = ({ property, model = property }) => { | ||
if ('function' === typeof model) { | ||
return model; | ||
} | ||
return ModelsMap[model] || ModelsMap[property]; | ||
} | ||
}; | ||
let modelLookup = defaultModelLookup; | ||
@@ -35,0 +35,0 @@ |
@@ -23,8 +23,8 @@ import _Map from 'babel-runtime/core-js/map'; | ||
function defaultModelLookup({ property, model = property }) { | ||
if (typeof model === 'function') { | ||
const defaultModelLookup = ({ property, model = property }) => { | ||
if ('function' === typeof model) { | ||
return model; | ||
} | ||
return ModelsMap[model] || ModelsMap[property]; | ||
} | ||
}; | ||
let modelLookup = defaultModelLookup; | ||
@@ -31,0 +31,0 @@ |
@@ -5,6 +5,6 @@ import getModelSchema from './schema'; | ||
function defaultModelLookup({ property, model = property }) { | ||
if (typeof model === 'function') { return model; } | ||
const defaultModelLookup = ({ property, model = property }) => { | ||
if ('function' === typeof model) { return model; } | ||
return ModelsMap[model] || ModelsMap[property]; | ||
} | ||
}; | ||
let modelLookup = defaultModelLookup; | ||
@@ -11,0 +11,0 @@ |
{ | ||
"name": "mobx-decorated-models", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "Decorators to make using Mobx for model type structures easier", | ||
@@ -5,0 +5,0 @@ "main": "dist/build.full.js", |
@@ -1,4 +0,4 @@ | ||
# Decorators for creating model type structures with mobx | ||
# Decorators for creating model relationships with mobx | ||
mobx-decorated-models is a collection of es7 decorators to make a class observable and serializable. | ||
mobx-decorated-models is a collection of Javascript decorators to make a classes and their relationships observable and serializable. | ||
@@ -9,17 +9,14 @@ [![Build Status](https://travis-ci.org/nathanstitt/mobx-decorated-models.svg?branch=master)](https://travis-ci.org/nathanstitt/mobx-decorated-models) | ||
[Mobx](https://mobx.js.org) makes state management super simple, but it doesn't offer an | ||
opinion on how to get data in and out of the observed data structures. | ||
This library is a collection of decorators that co-ordinates making | ||
models relate to each other and their fields both observable and serializable. | ||
It's built on top of two awesome libraries: | ||
[Mobx](https://mobx.js.org) makes state management super simple, but it doesn't offer an opinion on how to get data in and out of the observed data structures. | ||
[Serializr](https://github.com/mobxjs/serializr) takes care of that nicely. | ||
Combining the two libraries isn’t difficult, but then you end up specifing each attribute twice; | ||
once so Mobx will observe it, and once to create a schema for Serializr. | ||
Combining the two libraries isn’t difficult, but then you end up specifing each attribute twice; once so Mobx will observe it, and once to create a schema for Serializr. Enter mobx-decorated-models. | ||
This library is a collection of decorators that co-ordinates making | ||
fields both observable and serializable. | ||
While it’s at it, it also handles model lookups so different models can refer | ||
to one another regardless of import order. When one model refers to another, a | ||
reference of the requirement is stored and then later resolved when the class becomes known. | ||
## Example | ||
@@ -36,2 +33,3 @@ | ||
@field depth = 0; | ||
@session tmpContents = 'a bunch of things' | ||
@@ -58,3 +56,3 @@ @computed get volume() { | ||
console.log(box.volume); // => 48 | ||
console.log(box.serialize()); // => { id: 1, width: 2, height: 3, depth: 8, items: [] } | ||
console.log(box.serialize()); // => { id: 1, width: 2, height: 3, depth: 8, items: [] }; note `tmpContents` isn't serialized | ||
``` | ||
@@ -61,0 +59,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
221630
336