Skip to content

Instantly share code, notes, and snippets.

@colinbdclark
Created December 14, 2017 03:27
Show Gist options
  • Save colinbdclark/5b92588349bb1430fa74853256e72757 to your computer and use it in GitHub Desktop.
Save colinbdclark/5b92588349bb1430fa74853256e72757 to your computer and use it in GitHub Desktop.
Trouble with model relays in Aconite, simplified example
<html>
<head>
<script src="node_modules/infusion/dist/infusion-all.js"></script>
<script src="test.js"></script>
<style>
.model-updates {
font-family: monospace;
}
.old {
text-decoration: line-through;
background-color: pink;
}
.new {
background-color: lightgreen;
}
</style>
<title>Model Backpropagation Test</title>
</head>
<body>
<div class="model-updates"></div>
<script>
window.modelTest = colin.parentComponent(".model-updates");
</script>
</body>
</html>
"use strict";
fluid.defaults("colin.childComponent", {
gradeNames: "fluid.modelComponent",
model: {
hugo: "not hugo",
griffin: "tiny cat",
clovis: "CATTT"
}
});
fluid.defaults("colin.otherChildComponent", {
gradeNames: "fluid.modelComponent",
model: {
hugo: "not hugo",
mowgli: "mog",
arthur: "Giant"
},
components: {
peer: {
type: "fluid.mustBeOverridden"
}
}
});
fluid.defaults("colin.parentComponent", {
gradeNames: ["fluid.modelComponent", "fluid.viewComponent"],
model: {
hugo: "hugo",
griffin: "griffin"
},
components: {
child: {
type: "colin.childComponent",
options: {
gradeNames: ["colin.parentComponent.relayingChild"]
}
},
otherChild: {
type: "colin.otherChildComponent",
options: {
gradeNames: ["colin.parentComponent.relayingChild"],
components: {
peer: "{parentComponent}.child"
}
}
}
},
markup: {
log: "<p>%path: <span class='old'>%oldValue</span> <span class='new'>%value</span></p>"
}
});
colin.parentComponent.logModelChange = function (that, change) {
var logMarkup = fluid.stringTemplate(that.options.markup.log, change);
that.container.append(logMarkup);
};
fluid.defaults("colin.parentComponent.relayingChild", {
gradeNames: "fluid.modelComponent",
model: {},
modelRelay: {
source: "{parentComponent}.model",
target: "{that}.model",
backward: {
excludeSource: "init"
},
singleTransform: {
type: "fluid.transforms.identity"
}
},
modelListeners: {
"*": {
funcName: "colin.parentComponent.logModelChange",
args: ["{parentComponent}", "{change}"]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment