mobx-decorated-models
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -20,3 +20,3 @@ (function (global, factory) { | ||
var ModelsMap = new Map(); | ||
var ModelsMap = Object.create(null); | ||
@@ -147,3 +147,3 @@ var defaultModelLookup = function defaultModelLookup(_ref) { | ||
} | ||
var isObject = (typeof attrs === 'undefined' ? 'undefined' : _typeof(attrs)) === 'object'; | ||
var isObject = 'object' === (typeof attrs === 'undefined' ? 'undefined' : _typeof(attrs)); | ||
var canWrite = Object.isExtensible(attrs); | ||
@@ -153,3 +153,3 @@ | ||
if (defaultAttributes) { | ||
if (typeof defaultAttributes === 'function') { | ||
if ('function' === typeof defaultAttributes) { | ||
defaultAttributes = defaultAttributes.call(parentModel, array, parentModel); | ||
@@ -172,3 +172,3 @@ } | ||
var model = Klass && typeof Klass === 'function' && !(attrs instanceof Klass) ? new Klass(attrs) : attrs; | ||
var model = Klass && 'function' === typeof Klass && !(attrs instanceof Klass) ? new Klass(attrs) : attrs; | ||
@@ -451,7 +451,8 @@ if (inverseOf) { | ||
var array = mobx.observable.array(change.newValue); | ||
for (var i = 0; i < array.length; i += 1) { | ||
array[i] = setupModel({ | ||
attrs: array[i], | ||
array: array, | ||
var array = mobx.observable.array([]); | ||
for (var i = 0; i < change.newValue.length; i += 1) { | ||
array.push(setupModel({ | ||
attrs: change.newValue[i], | ||
array: change.newValue, | ||
modelClass: modelClass, | ||
@@ -462,3 +463,3 @@ defaultAttributes: defaultAttributes, | ||
parentModelProp: parentModelProp | ||
}); | ||
})); | ||
} | ||
@@ -535,3 +536,3 @@ if (parentModel[parentModelProp]) { | ||
function buildAttributeDecorator(type, args, setAttributeFn) { | ||
if (_typeof(args[0]) === 'object' && args.length === 1) { | ||
if ('object' === _typeof(args[0]) && 1 === args.length) { | ||
return function (target, property, descriptor) { | ||
@@ -538,0 +539,0 @@ return addAttribute(type, setAttributeFn, target, property, descriptor, args[0]); |
@@ -17,3 +17,3 @@ import { SKIP, createModelSchema, custom, deserialize, getDefaultModelSchema, identifier, list, object, primitive, serialize, update } from 'serializr'; | ||
var ModelsMap = new Map(); | ||
var ModelsMap = Object.create(null); | ||
@@ -144,3 +144,3 @@ var defaultModelLookup = function defaultModelLookup(_ref) { | ||
} | ||
var isObject = (typeof attrs === 'undefined' ? 'undefined' : _typeof(attrs)) === 'object'; | ||
var isObject = 'object' === (typeof attrs === 'undefined' ? 'undefined' : _typeof(attrs)); | ||
var canWrite = Object.isExtensible(attrs); | ||
@@ -150,3 +150,3 @@ | ||
if (defaultAttributes) { | ||
if (typeof defaultAttributes === 'function') { | ||
if ('function' === typeof defaultAttributes) { | ||
defaultAttributes = defaultAttributes.call(parentModel, array, parentModel); | ||
@@ -169,3 +169,3 @@ } | ||
var model = Klass && typeof Klass === 'function' && !(attrs instanceof Klass) ? new Klass(attrs) : attrs; | ||
var model = Klass && 'function' === typeof Klass && !(attrs instanceof Klass) ? new Klass(attrs) : attrs; | ||
@@ -448,7 +448,8 @@ if (inverseOf) { | ||
var array = observable.array(change.newValue); | ||
for (var i = 0; i < array.length; i += 1) { | ||
array[i] = setupModel({ | ||
attrs: array[i], | ||
array: array, | ||
var array = observable.array([]); | ||
for (var i = 0; i < change.newValue.length; i += 1) { | ||
array.push(setupModel({ | ||
attrs: change.newValue[i], | ||
array: change.newValue, | ||
modelClass: modelClass, | ||
@@ -459,3 +460,3 @@ defaultAttributes: defaultAttributes, | ||
parentModelProp: parentModelProp | ||
}); | ||
})); | ||
} | ||
@@ -532,3 +533,3 @@ if (parentModel[parentModelProp]) { | ||
function buildAttributeDecorator(type, args, setAttributeFn) { | ||
if (_typeof(args[0]) === 'object' && args.length === 1) { | ||
if ('object' === _typeof(args[0]) && 1 === args.length) { | ||
return function (target, property, descriptor) { | ||
@@ -535,0 +536,0 @@ return addAttribute(type, setAttributeFn, target, property, descriptor, args[0]); |
import getModelSchema from './schema'; | ||
const ModelsMap = new Map(); | ||
const ModelsMap = Object.create(null); | ||
@@ -5,0 +5,0 @@ const defaultModelLookup = ({ property, model = property }) => { |
@@ -10,4 +10,6 @@ import { observable, intercept } from 'mobx'; | ||
function onPropertySet(change, | ||
{ modelClass, defaultAttributes, inverseOf, parentModel, parentModelProp }) { | ||
function onPropertySet( | ||
change, | ||
{ modelClass, defaultAttributes, inverseOf, parentModel, parentModelProp } | ||
) { | ||
change.newValue = setupModel({ | ||
@@ -29,13 +31,16 @@ attrs: change.newValue, | ||
} = options; | ||
const array = observable.array(change.newValue); | ||
for (let i = 0; i < array.length; i += 1) { | ||
array[i] = setupModel({ | ||
attrs: array[i], | ||
array, | ||
modelClass, | ||
defaultAttributes, | ||
inverseOf, | ||
parentModel, | ||
parentModelProp, | ||
}); | ||
const array = observable.array([]); | ||
for (let i = 0; i < change.newValue.length; i += 1) { | ||
array.push( | ||
setupModel({ | ||
attrs: change.newValue[i], | ||
array: change.newValue, | ||
modelClass, | ||
defaultAttributes, | ||
inverseOf, | ||
parentModel, | ||
parentModelProp, | ||
}), | ||
); | ||
} | ||
@@ -100,3 +105,3 @@ if (parentModel[parentModelProp]) { | ||
function buildAttributeDecorator(type, args, setAttributeFn) { | ||
if ((typeof args[0] === 'object') && args.length === 1) { | ||
if (('object' === typeof args[0]) && 1 === args.length) { | ||
return (target, property, descriptor) => | ||
@@ -103,0 +108,0 @@ addAttribute(type, setAttributeFn, target, property, descriptor, args[0]); |
@@ -8,3 +8,3 @@ import { markNonserializable } from './serializable'; | ||
if (!attrs) { return attrs; } | ||
const isObject = (typeof attrs === 'object'); | ||
const isObject = ('object' === typeof attrs); | ||
const canWrite = Object.isExtensible(attrs); | ||
@@ -14,3 +14,3 @@ | ||
if (defaultAttributes) { | ||
if (typeof defaultAttributes === 'function') { | ||
if ('function' === typeof defaultAttributes) { | ||
defaultAttributes = defaultAttributes.call(parentModel, array, parentModel); | ||
@@ -33,4 +33,4 @@ } | ||
const model = (Klass && typeof Klass === 'function' && !(attrs instanceof Klass)) ? | ||
new Klass(attrs) : attrs; | ||
const model = (Klass && 'function' === typeof Klass && !(attrs instanceof Klass)) ? | ||
new Klass(attrs) : attrs; | ||
@@ -37,0 +37,0 @@ if (inverseOf) { |
{ | ||
"name": "mobx-decorated-models", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Decorators to make using Mobx for model type structures easier", | ||
@@ -5,0 +5,0 @@ "main": "dist/build.full.js", |
@@ -192,3 +192,3 @@ import { autorun } from 'mobx'; | ||
fit('can use a custom type', () => { | ||
it('can use a custom type', () => { | ||
const ship = Ship.deserialize({ radio: '156.750mhz' }); | ||
@@ -195,0 +195,0 @@ expect(ship.radio).toBeInstanceOf(Radio); |
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 not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
233176
1873
34