Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-g/8008f24f8f8340d80723 to your computer and use it in GitHub Desktop.
Save jakub-g/8008f24f8f8340d80723 to your computer and use it in GitHub Desktop.
Aria Templates common mistakes: not using $json.setValue
{
"name": "Aria Templates common mistakes: not using $json.setValue",
"description": "When you forget to use setValue for updating the data model entry, none of defined data binding refreshes will occur",
"data": {
"counter": 0
}
}
{macro main()}
<button {on click "updateModelBad" /}>Update counter</button>
<button {on click "updateModelBetter" /}>Update counter (better)</button>
<br>
Counter has value of: {@aria:Text {
text : this.data.counter,
bind : {
text : {
inside: this.data,
to: "counter"
}
}
}/}
{/macro}
({
$classpath:'InstantTemplateScript',
$prototype : {
updateModelBad: function() {
// just updates the value in data model
// won't trigger all the updates defined through data binding
this.data.counter++;
alert("counter is " + this.data.counter);
},
updateModelBetter: function() {
// better, this will trigger all the refreshes
this.$json.setValue(this.data, "counter", this.data.counter + 1);
alert("counter is " + this.data.counter);
}
}
})
@jakub-g
Copy link
Author

jakub-g commented Oct 17, 2014

Created by Instant Aria Templates, viewable on http://instant.ariatemplates.com/jakub-g/8008f24f8f8340d80723

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