mobx-decorated-models
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -67,6 +67,17 @@ (function (global, factory) { | ||
function objectSerializer() { | ||
return { | ||
serializer: function serializer(obj) { | ||
return obj.toJS(); | ||
}, | ||
deserializer: function deserializer(json, cb) { | ||
cb(null, mobx.observable.map(json)); | ||
} | ||
}; | ||
} | ||
function getSerializer(options, defaultSerializer) { | ||
var serializer = void 0; | ||
if (options.type === 'object') { | ||
serializer = serializr.map; | ||
serializer = objectSerializer; | ||
} else if (options.type === 'array') { | ||
@@ -73,0 +84,0 @@ serializer = serializr.list; |
@@ -1,2 +0,2 @@ | ||
import { createModelSchema, deserialize, getDefaultModelSchema, identifier, list, map, object, primitive, serialize, update } from 'serializr'; | ||
import { createModelSchema, deserialize, getDefaultModelSchema, identifier, list, object, primitive, serialize, update } from 'serializr'; | ||
import { action, observable } from 'mobx'; | ||
@@ -64,6 +64,17 @@ | ||
function objectSerializer() { | ||
return { | ||
serializer: function serializer(obj) { | ||
return obj.toJS(); | ||
}, | ||
deserializer: function deserializer(json, cb) { | ||
cb(null, observable.map(json)); | ||
} | ||
}; | ||
} | ||
function getSerializer(options, defaultSerializer) { | ||
var serializer = void 0; | ||
if (options.type === 'object') { | ||
serializer = map; | ||
serializer = objectSerializer; | ||
} else if (options.type === 'array') { | ||
@@ -70,0 +81,0 @@ serializer = list; |
import { | ||
serialize, deserialize, createModelSchema, primitive, list, object, | ||
identifier, getDefaultModelSchema, update, map, | ||
identifier, getDefaultModelSchema, update, | ||
} from 'serializr'; | ||
import { | ||
observable, | ||
} from 'mobx'; | ||
@@ -21,6 +24,13 @@ import { registerModel, findModel } from './model-lookup'; | ||
function objectSerializer() { | ||
return { | ||
serializer(obj) { return obj.toJS(); }, | ||
deserializer(json, cb) { cb(null, observable.map(json)); }, | ||
}; | ||
} | ||
function getSerializer(options, defaultSerializer) { | ||
let serializer; | ||
if (options.type === 'object') { | ||
serializer = map; | ||
serializer = objectSerializer; | ||
} else if (options.type === 'array') { | ||
@@ -27,0 +37,0 @@ serializer = list; |
{ | ||
"name": "mobx-decorated-models", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Decorators to make using Mobx for model type structures easier", | ||
@@ -5,0 +5,0 @@ "main": "dist/build.full.js", |
@@ -31,2 +31,20 @@ import { Container, Box } from './test-models'; | ||
it('can serialize/deserialize nested objects', () => { | ||
const box = new Box(); | ||
box.update({ | ||
metadata: { | ||
one: 1, | ||
two: ['one', 'three'], | ||
four: { test: true }, | ||
}, | ||
}); | ||
expect(box.serialize().metadata).toEqual( | ||
expect.objectContaining({ | ||
one: 1, | ||
four: expect.objectContaining({ test: true }), | ||
two: expect.arrayContaining(['one', 'three']), | ||
}), | ||
); | ||
}); | ||
it('adds update method to prototype', () => { | ||
@@ -33,0 +51,0 @@ const attrs = { id: 2, width: 3, depth: 12, height: 4, container: { |
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
178113
1126
23