tonyg / syndicate

syn·di·cate: a language for interactive programs
http://syndicate-lang.org/
GNU Lesser General Public License v3.0
152 stars 11 forks source link

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

Open tonyg opened 7 years ago

tonyg commented 7 years ago

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.