Skip to content

Instantly share code, notes, and snippets.

@amb26
Created January 28, 2015 19:47
Show Gist options
  • Select an option

  • Save amb26/38cf42a2c57224c01a1c to your computer and use it in GitHub Desktop.

Select an option

Save amb26/38cf42a2c57224c01a1c to your computer and use it in GitHub Desktop.
FLUID-5517 test case demonstrating FLOE-230 failure
// FLUID-5517: Failure to batch compound updates properly - example from metadata feedback
fluid.defaults("fluid.tests.fluid5517root", {
gradeNames: ["fluid.standardRelayComponent", "autoInit"],
model: {
userData: {
opinion: {
mismatch: true
}
},
inTransit: {
opinion: ["dislike"] // Possible values: like, dislike
}
},
modelRelay: [{
source: "{that}.model.inTransit.opinion",
target: "{that}.model.userData.opinion",
forward: "liveOnly",
singleTransform: {
type: "fluid.transforms.arrayToSetMembership",
options: {
"like": "match",
"dislike": "mismatch"
}
}
}],
events: {
onFeedbackMarkupReady: null
},
components: {
bindMatchConfirmation: {
type: "fluid.standardRelayComponent",
createOnEvent: "onFeedbackMarkupReady",
options: {
modelRelay: {
source: "{fluid5517root}.model.inTransit",
target: "{that}.model.isActive",
backward: "liveOnly",
transform: {
transform: {
type: "fluid.transforms.arrayToSetMembership",
inputPath: "opinion",
options: {
"like": ""
}
}
}
}
}
},
bindMismatchDetails: {
type: "fluid.standardRelayComponent",
createOnEvent: "onFeedbackMarkupReady",
options: {
modelRelay: {
source: "{fluid5517root}.model.inTransit",
target: "{that}.model.isActive",
backward: "liveOnly",
transform: {
transform: {
type: "fluid.transforms.arrayToSetMembership",
inputPath: "opinion",
options: {
"dislike": ""
}
}
}
}
}
}
}
});
fluid.tests.dumpModel = function (that) {
console.log("Root model: ", JSON.stringify(that.model, null, 2));
if (that.bindMatchConfirmation) {
console.log("Match model: ", JSON.stringify(that.bindMatchConfirmation.model, null, 2));
console.log("Mismatch model: ", JSON.stringify(that.bindMismatchDetails.model, null, 2));
}
};
jqUnit.test("FLUID-5517: Batching failure in model relay", function () {
var that = fluid.tests.fluid5517root();
jqUnit.assertDeepEq("Initial model synchronised", ["dislike"], that.model.inTransit.opinion);
fluid.tests.dumpModel(that);
console.log("=============================== FIRING ATTACHMENT EVENT ================");
that.events.onFeedbackMarkupReady.fire();
fluid.tests.dumpModel(that);
that.applier.change("userData.opinion.match", true);
jqUnit.assertDeepEq("Stabilised model synchronised", ["like"], that.model.inTransit.opinion);
fluid.tests.dumpModel(that);
});
OUTPUT AFTER firing change from line 89:
Root model:
{
"userData": {
"opinion": {
"mismatch": true,
"match": false
}
},
"inTransit": {
"opinion": [
"dislike"
]
}
}
Match model:
{
"isActive": false
}
Mismatch model:
{
"isActive": true
}
setMembershipToArray making output ["like","dislike"] given options {"match":"like","mismatch":"dislike"}
arrayToSetMembership with options {"like":"match","dislike":"mismatch"} and input value ["like","dislike"]
arrayToSetMembership setting path match to true
arrayToSetMembership setting path mismatch to true
arrayToSetMembership with options {"like":""} and input value ["like","dislike"]
arrayToSetMembership setting path to true
setMembershipToArray making output ["like"] given options {"":"like"} <------ PROBLEM HERE! target array has been overwritten with this incomplete relay result
@amb26
Copy link
Copy Markdown
Author

amb26 commented Jan 28, 2015

Note - the "proper" solution to this problem (or rather, the only one we can implement without stateful relay rules) is simple-seeming but rather obscure - it was explained in IRC at https://botbot.me/freenode/fluid-work/2014-08-25/?msg=20363141&page=2

The idea is to tackle the issue at the point of initial data binding - the UI action of selecting, say, the "match" button is not bound to the boolean end of the relay, but the array and - and the binding has the effect, say, of writing the entire array ["match"] to the so-called "inTransit.opinion" (this needs to be renamed) - rather than writing to the boolean end of the relay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment