Is there any way to insert a callback before/after a templates context is updated?
Asked Answered
V

1

0

I'm aware of Template.onRendered, however I have the need to destroy and setup some plugins that act on the dom when the actual context is updated.

So saying I have content template, I'd need something similar to the following:

Template.content.onBeforeChange(function () {
  $(".editor").editable("destroy");
});

Template.content.onAfterChange(function () {
  $(".editor").editable();
});

Is there any current way I can achieve this with the existing Template api?

Vookles answered 2/4, 2015 at 17:1 Comment(0)
B
3

You should be able to detect a context change within a template autorun by looking at currentData like this:

Template.content.onRendered(function() {
  this.autorun(function() {
    if (Template.currentData()) {
      // the context just changed - insert code here
    }
  });
});

I'm unclear if that works for your particular case because this technique only gets you the equivalent of onAfterChange.

Biblical answered 2/4, 2015 at 17:18 Comment(1)
You're correct, though looking into it, it appears that the blaze template system wouldn't support a callback before the context is updated. So this will be the answer, thank you :)Vookles

© 2022 - 2024 — McMap. All rights reserved.