blaze-local-state
Local reactive state for Blaze templates
A package that gives Blaze templates their own local state, so each template instance can track values like counters without sharing a global session.
This package solves a common problem in Blaze templates (a templating system for building web interfaces) where developers need to keep track of changing data that's specific to one template instance.
Normally, developers use a global "Session" to store values like counters or form inputs. The problem is that this global storage gets messy: if you have the same template used twice on a page, both instances share the same counter, making it hard to keep them independent. You also have to write a lot of boilerplate code to set up helpers and manage state changes. This package cuts through that by letting you define local state that belongs to a single template instance, similar to how component state works in modern frameworks.
Here's how it works in practice: instead of manually creating helpers and event handlers that read from and write to a global Session, you tell your template "here's the initial state I want" (like { counter: 0 }), and the package automatically makes it available. Within your template's event handlers, you can then call simple methods like template.get('counter') and template.set('counter', newValue) to read and update that state. When the state changes, the template re-renders automatically to show the new value.
This would be useful for any Blaze developer building interactive templates—think of a form where you're tracking validation errors, a carousel tracking which slide is active, or a dropdown tracking whether it's open or closed. Instead of polluting your global Session namespace or repeating the same boilerplate, you keep the state local and tidy.
The tradeoff is that this only works within Blaze; if you're using a modern framework like Vue or React, you'd have similar state management features built in. But for Blaze projects, it's a practical way to write less code and avoid common bugs from shared global state.
Where it fits
- Track per-instance state like form validation errors without polluting the global Session.
- Manage which carousel slide or dropdown is active independently across multiple template copies.
- Reduce boilerplate helpers and event handlers for simple template-local state.