Installation
Overview
ReactiveDict provides:- Reactive key-value storage - Like Session, but scoped
- Hot Code Push persistence - Optionally preserve state across reloads
- EJSON values - Store any EJSON-serializable value
- Fine-grained reactivity - Only invalidate when specific keys change
- Multiple instances - Create as many dictionaries as needed
Package Information
- Version: 1.3.2
- Summary: Reactive dictionary
- Dependencies:
tracker,ejson,mongo(weak),reload(weak) - Export:
ReactiveDict
Basic Usage
Creating a ReactiveDict
Optional name for the dictionary. Named dictionaries are preserved across Hot Code Push.
Optional object with initial key-value pairs
Setting Values
Getting Values
Constructor
Anonymous Dictionary
Named Dictionary
Methods
set(key, value) or set(object)
Set one or more key-value pairs:The key to set (when setting single value)
The value to set (must be EJSON-serializable)
get(key)
Get a value and establish reactive dependency:The key to retrieve
undefined if key doesn’t exist.
setDefault(key, value)
Set a value only if the key doesn’t exist:all()
Get all key-value pairs as an object:Calling
all() creates a dependency on every key in the dictionary.clear()
Remove all keys:delete(key)
Remove a specific key:equals(key, value)
Reactively check if a key equals a value:equals() is more efficient than get() when you only care about a specific value.Reactivity
Key-Level Reactivity
ReactiveDict invalidates only computations that depend on changed keys:Reactive Patterns
Common Patterns
Pattern: Form State Management
Pattern: Component State
Pattern: Loading States
Pattern: Feature Flags
Using with React
Persistence
Hot Code Push Persistence
Named ReactiveDict instances are automatically preserved across hot code push:Persistence only works on the client and only for hot code push, not full page reloads.
Manual Serialization
Comparison with Session
ReactiveDict
Session (deprecated)
Performance Tips
Debugging
Related Packages
reactive-var
Single reactive values
tracker
Reactive computation system
session
Global reactive dictionary (deprecated)