Is Template.vars still coming to Blaze?


#1

@sashko wrote about Template.vars on Medium a while back, but as far as I can tell it hasn’t happened yet. Or am I missing something?

Is that still planned? I like having lots of reactive state rather than doing $(…).something() and I want those things scoped as locally as possible rather than in the session.


#2

For reactive states local to a template, use ReactiveVar.


#3

For sure that works (though ReactiveDict is better because it can be preserved across hot code pushes), but the problem is that you need to write a bunch of boilerplate to make that work. You need to set up the var and create a helper.


#4

Yes you do. For future changes, maybe you can find something here.


#5

I think it’s not going to be shipped soon, but it’s something that should be able to be implemented in a package via monkey-patching.

You could override the template constructor to automatically add an onCreated hook to create this.state, and create a global helper for Template.state.

Basically, like you said, it’s already possible, and you could create a package to remove boilerplate.


#6

Thanks, I’ll probably do that!