Last active
August 29, 2015 14:07
-
-
Save jakub-g/8008f24f8f8340d80723 to your computer and use it in GitHub Desktop.
Aria Templates common mistakes: not using $json.setValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
$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); | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{macro main()} | |
{/macro} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created by Instant Aria Templates, viewable on http://instant.ariatemplates.com/jakub-g/8008f24f8f8340d80723