What I would like to do is attach a jQuery handler after the things are loaded on the page. In the template JS file things is a helper like the following:
In general, it’s better to put your jquery handlers in onRendered and to fully understand the cases where your template is re-rendered such that you need to re-trigger. Relying on setTimeout, or Tracker.afterFlush may work 99% of the time, but it can indicate that you don’t understand all the ways that reactivity may cause your UI to change - which can cause problems down the road.
Parent -> child can be accomplished in a couple of ways:
changing the data context (note that you’ll be back in the same place if changing data re-renders the UI).
Using Blaze.getView with an element rendered by the child template, and then getting the parent of the view until you get the child template instance.
Technically you can call templateInstance.getChild(templateName) - but I’m not sure how that works when you render the same child template multiple times (e.g., thingTemplate).
Child -> Parent:
Pass in a reactive var as part of the data, the child can set state on this var and autorun blocks in the parent that depend on it will run
Pass in a callback function as part of the data to the child, the child can call this function like any other.
event handlers attached to elements rendered by the child.
calling templateInstance.parent()
I don’t love any of these approaches of child -> parent. I’ve never needed parent -> child beyond just changing the data I pass in.
One thing to note on @jamgold’s solution is that if your thing changes, or you need to attach a jquery handler across multiple of those (e.g., a sortable with different lists) you’ll end up in the same situation, where you need to “update” the handler when the data changes. But if this isn’t your situation then it’s for sure a cleaner approach.
Having a quick look, the initialisation would have to be in onRendered but blaze event listeners should receive the sortable events.
jQuery is pretty good about using native events, and even when not, it helps that the backend for blaze (including event handlers) is done through jquery