Skip to content

ui.js: Monitor parent context changes in child contexts #16

Description

@tonyg

ui.js: Monitor parent context changes in child contexts. There's a lot of faff in webchat.syndicate.js about publishing some HTML, waiting for it to appear, and then configuring some aspect of event listening or child HTML insertion. It'd be nice if the hierarchical UIFragment context identifiers could be used to allow all-at-once creation of resources and self-assembly of the DOM fragments and event handlers as their parents reconfigure themselves.

For example:

during inbound(uiTemplate("post-item.html", $postItemTemplate)) {
  during inbound(uiTemplate("post-item-" + contentClass + ".html", $entry)) {
    assert uiContext.html(containerSelector, Mustache.render(postItemTemplate, itemInfo));
    on asserted uiContext.fragmentVersion(_) {
      var innerContext = uiContext.context('item-body');
      assert innerContext.html('#' + itemId + ' .post-item-body-container',
                               Mustache.render(entry, itemInfo));
      if (!postInfo.isDraft) { /* ... */ }
    }
  }
}

could be rewritten as:

during inbound(uiTemplate("post-item.html", $postItemTemplate)) {
  during inbound(uiTemplate("post-item-" + contentClass + ".html", $entry)) {
    assert uiContext.html(containerSelector, Mustache.render(postItemTemplate, itemInfo));
    var innerContext = uiContext.context('item-body');
    assert innerContext.html('#' + itemId + ' .post-item-body-container',
                             Mustache.render(entry, itemInfo));
    if (!postInfo.isDraft) { /* ... */ }
  }
}

and the waiting-for-fragmentVersion would be done automatically in ui.js.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions