Right, after a lot of headaches I’ve got it working - thanks for the help!
The two other problems I hit which could possibly do with some re-engineering in the widget code:
When setting dirtyKeys, it only re-renders the first widget with that buildKey. I’ve got around that by adding the post-id to the post-avatar’s buildKey so that every buildKey is unique
Setting the dirtyKey doesn’t work if the widget you want to re-render is inside another widget. In my case the post-avatar is inside a post. I think this is because of the shadowTree stuff.
It would be really nice if the widget code could work out that the widget is deep in the tree and re-render its parents. I’ve got around this by setting the post widget as dirty as well.
That’s because keys are supposed to be unique! So adding the post id to the avatar is correct in this case. I might want to raise an error in development mode if two elements use the same keys. If you want to commit the post avatar key to master that would be fine.
That’s exactly what it is. By default I think a widget is supposed to re-render its parents, but the shadowTree is a performance optimization that avoids too much re-rendering and requires you to be more explicit.
Just in case anyone is trying to track down how widgets can use handlebars templates, see the commit message here (can’t find it documented anywhere on meta):
Weird, for me when I try that component it doesn’t render at all because it is missing a key. I’ve updated the documentation above to add a buildKey method and it’s working for me. Try that out.
It depends on your widget. In @eviltrout’s example, the my-widget expects to be passed an action named “deleteThing”. Different widgets will use different names for their actions (and indeed, it’s possible for them to call their action “action”)