mobx-decorated-models
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -70,3 +70,3 @@ (function (global, factory) { | ||
serializer: function serializer(obj, prop, parent) { | ||
return isSerializable(parent, prop) ? obj : undefined; | ||
return isSerializable(parent, prop) ? obj : serializr.SKIP; | ||
}, | ||
@@ -111,3 +111,3 @@ deserializer: function deserializer(json, cb) { | ||
serializer: function serializer() { | ||
return undefined; | ||
return serializr.SKIP; | ||
}, | ||
@@ -160,3 +160,3 @@ deserializer: fns.deserializer | ||
if (!isSerializable(parent, name)) { | ||
return undefined; | ||
return serializr.SKIP; | ||
} | ||
@@ -163,0 +163,0 @@ return defaultSerializer.serializer(belongsTo); |
@@ -1,2 +0,2 @@ | ||
import { createModelSchema, custom, deserialize, getDefaultModelSchema, identifier, list, object, primitive, serialize, update } from 'serializr'; | ||
import { SKIP, createModelSchema, custom, deserialize, getDefaultModelSchema, identifier, list, object, primitive, serialize, update } from 'serializr'; | ||
import { intercept, observable } from 'mobx'; | ||
@@ -67,3 +67,3 @@ | ||
serializer: function serializer(obj, prop, parent) { | ||
return isSerializable(parent, prop) ? obj : undefined; | ||
return isSerializable(parent, prop) ? obj : SKIP; | ||
}, | ||
@@ -108,3 +108,3 @@ deserializer: function deserializer(json, cb) { | ||
serializer: function serializer() { | ||
return undefined; | ||
return SKIP; | ||
}, | ||
@@ -157,3 +157,3 @@ deserializer: fns.deserializer | ||
if (!isSerializable(parent, name)) { | ||
return undefined; | ||
return SKIP; | ||
} | ||
@@ -160,0 +160,0 @@ return defaultSerializer.serializer(belongsTo); |
import { | ||
serialize, deserialize, createModelSchema, primitive, list, object, | ||
serialize, deserialize, createModelSchema, primitive, list, object, SKIP, | ||
identifier, getDefaultModelSchema, update, custom as customSerializer, | ||
@@ -8,3 +8,3 @@ } from 'serializr'; | ||
import { | ||
isSerializable, markNonserializable | ||
isSerializable, markNonserializable, | ||
} from './serializable'; | ||
@@ -18,3 +18,3 @@ import getSchema from './schema'; | ||
serializer(obj, prop, parent) { | ||
return isSerializable(parent, prop) ? obj : undefined; | ||
return isSerializable(parent, prop) ? obj : SKIP; | ||
}, | ||
@@ -58,3 +58,3 @@ deserializer(json, cb) { | ||
return { | ||
serializer: () => undefined, | ||
serializer: () => SKIP, | ||
deserializer: fns.deserializer, | ||
@@ -100,3 +100,3 @@ }; | ||
serializer(belongsTo, name, parent) { | ||
if (!isSerializable(parent, name)) { return undefined; } | ||
if (!isSerializable(parent, name)) { return SKIP; } | ||
return defaultSerializer.serializer(belongsTo); | ||
@@ -103,0 +103,0 @@ }, |
{ | ||
"name": "mobx-decorated-models", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Decorators to make using Mobx for model type structures easier", | ||
@@ -13,3 +13,3 @@ "main": "dist/build.full.js", | ||
"mobx": "^3.0.2", | ||
"serializr": "https://github.com/nathanstitt/serializr#serializer-args" | ||
"serializr": "1.1.11" | ||
}, | ||
@@ -16,0 +16,0 @@ "scripts": { |
@@ -152,2 +152,23 @@ # Decorators for creating model type structures with mobx | ||
### session | ||
Session fields are useful for storing data that should not be persisted. | ||
They're write-only, meaning they're updated by the `deserialize` static method and `update()` instance method, but are not included in the JSON generated by `serialize()` | ||
*example:* | ||
```javascript | ||
@identifiedBy('user') | ||
class User { | ||
@field id; | ||
@session isLoggedIn; | ||
} | ||
const user = new User(); | ||
user.update({ id: 1234, isLoggedIn: true }); | ||
user.serialize(); // => { id: 1234 }; // note the "isLoggedIn" property is ommited | ||
``` | ||
### belongsTo | ||
@@ -302,6 +323,1 @@ | ||
``` | ||
# Future plans | ||
* Sessions: properties that will be set from JSON but won't be serialized. https://github.com/mobxjs/serializr/pull/32 is needed before this can be supported |
@@ -67,3 +67,3 @@ import { autorun } from 'mobx'; | ||
it('merges both attributes and session props', () => { | ||
it('session props are set but not serialized', () => { | ||
const box = Box.deserialize({ width: 3, color: 'red' }); | ||
@@ -70,0 +70,0 @@ expect(box.color).toEqual('red'); |
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
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
217564
322
0
0
+ Addedserializr@1.1.11(transitive)
Updatedserializr@1.1.11