Basically, instead of generating script tag markers with mostly arbitrary numbers, have them be a stringification of the data keys. For example:
Sample json:
{
user: {
name: 'devinrhode1'
}
}
Render with template:
<h1> Welcome {{user.name}}</h1>
Produces:
<h1> Welcome
<script id="ember-start-user.name"></script>
devinrhode1
<script id="ember-end-user.name"></script>
</h1>
This moves towards having an initial state rendered server side, as @tomdale just mentioned in a talk tonight.
When you get an update of this json:
{
user: {
name: 'devinrhode2'
}
}
There's a simple convention to update the page. Here's a very rough outline of the code:
for (var key in update) {
// No strings/numbers at top level, so we would recurse.
getElementById('ember-start-'+ *data key 1 (user)* + *data key 2 (name) ).innerHTML = thatNewDataBrah;
}
For arrays, my best idea is to embed the indices into the id's.
Basically, instead of generating script tag markers with mostly arbitrary numbers, have them be a stringification of the data keys. For example:
Sample json:
Render with template:
Produces:
This moves towards having an initial state rendered server side, as @tomdale just mentioned in a talk tonight.
When you get an update of this json:
There's a simple convention to update the page. Here's a very rough outline of the code:
For arrays, my best idea is to embed the indices into the id's.