Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTrigger does not respect serializable attribute #1982

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve DataTrigger serialization spec
  • Loading branch information
tejaede committed May 31, 2018
commit 43211d42650dc2dbb4f0c3374c91386fba6fc095
2 changes: 2 additions & 0 deletions data/service/data-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ Object.defineProperties(exports.DataTrigger, /** @lends DataTrigger */ {
_addTrigger: {
value: function (service, objectDescriptor, prototype, name) {
var descriptor = objectDescriptor.propertyDescriptorForName(name),
serializable = Montage.getPropertyAttribute(prototype, name, "serializable"),
trigger;
if (descriptor) {
trigger = Object.create(this._getTriggerPrototype(service));
Expand All @@ -515,6 +516,7 @@ Object.defineProperties(exports.DataTrigger, /** @lends DataTrigger */ {
}
});
} else {
console.log("Serializable", name, serializable);
Montage.defineProperty(prototype, name, {
get: function () {
return trigger._getValue(this);
Expand Down
85 changes: 68 additions & 17 deletions test/spec/data/data-trigger.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
var DataOperation = require("montage/data/service/data-operation").DataOperation,
DataTrigger = require("montage/data/service/data-trigger").DataTrigger,
var DataTrigger = require("montage/data/service/data-trigger").DataTrigger,
DataService = require("montage/data/service/data-service").DataService,
DataOperationType = require("montage/data/service/data-operation-type").DataOperationType,
Deserializer = require("montage/core/serialization/deserializer/montage-deserializer").MontageDeserializer,
deserialize = require("montage/core/serialization/deserializer/montage-deserializer").deserialize,
Serializer = require("montage/core/serialization/serializer/montage-serializer").MontageSerializer,
serialize = require("montage/core/serialization/serializer/montage-serializer").serialize,
Montage = require("montage").Montage,
ObjectDescriptor = require("montage/core/meta/object-descriptor").ObjectDescriptor,
PropertyDescriptor = require("montage/core/meta/property-descriptor").PropertyDescriptor;
Expand All @@ -14,36 +8,92 @@ var DataOperation = require("montage/data/service/data-operation").DataOperation

var ModelObject = Montage.specialize({


//Serializable (has get & set)
ancestors: {
get: function () {
if (!this._ancestors) {
this._ancestors = [];
}
return this._ancestors;
},
set: function (value) {
this._ancestors = value;
}
},

//NOT Serializable (serializable attribute is false)
children: {
get: function () {
if (!this._children) {
this._children = [];
}
return this._children;
},
set: function (value) {
this._ancestors = value;
},
serializable: false
},

ancestors: {
//Serializable
siblings: {
value: undefined
},

//NOT Serializable (not writable)
cousins: {
value: undefined,
writable: false
},

//NOT Serializable (serializable attribute is false)
friends: {
value: undefined,
serializable: false
},



//NOT Serializable (not writable)
aunts: {
get: function () {
if (!this._ancestors) {
this._ancestors = [];
if (!this._aunts) {
this._aunts = [];
}
return this._ancestors;
return this._aunts;
}
},

//NOT Serializable (not writable & serializable attribute is false)
uncles: {
get: function () {
if (!this._uncles) {
this._uncles = [];
}
return this._uncles;
},
serializable: false
}
});

var ModelDescriptor = new ObjectDescriptor().initWithName("ModelObject");
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("children", ModelDescriptor, 1));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("ancestors", ModelDescriptor, 1));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("ancestors", ModelDescriptor, Infinity));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("children", ModelDescriptor, Infinity));

ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("siblings", ModelDescriptor, Infinity));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("cousins", ModelDescriptor, Infinity));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("friends", ModelDescriptor, Infinity));

ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("aunts", ModelDescriptor, Infinity));
ModelDescriptor.addPropertyDescriptor(new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("uncles", ModelDescriptor, Infinity));

describe("A DataTrigger", function() {

it("can respect serializable property", function () {
// Mimics DataService#_prototypeForType
var prototype = Object.create(ModelObject.prototype),
requisites = new Set("children", "ancestors"),
requisites = new Set(),
service = new DataService(),
cleanInstanceObjectCreate, cleanObjectCreatePropertyNames,
cleanInstanceConstructor, cleanInstancePropertyNames,
Expand All @@ -57,13 +107,14 @@ describe("A DataTrigger", function() {
cleanInstanceConstructor = new ModelObject();

triggerPropertyNames = Montage.getSerializablePropertyNames(triggerInstance);
console.log("Triggered", propertyNames);
console.log("Triggered", triggerPropertyNames);

cleanObjectCreatePropertyNames = Montage.getSerializablePropertyNames(cleanInstanceObjectCreate);
console.log("Object.create", propertyNames);
console.log("Object.create", cleanObjectCreatePropertyNames);

cleanInstancePropertyNames = Montage.getSerializablePropertyNames(cleanInstanceConstructor);
console.log("Constructor", propertyNames);
console.log("Constructor", cleanInstancePropertyNames);

expect(triggerPropertyNames).toEqual(["children", "ancestors", "identifier"]);
expect(triggerPropertyNames).toEqual(cleanObjectCreatePropertyNames);
expect(cleanObjectCreatePropertyNames).toEqual(cleanInstancePropertyNames);
Expand Down