Skip to content

Idea: data key to id convention #18

Description

@devinrhode2

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions