meteorflux
meteorflux copied to clipboard
How to actually set state?
I must be missing something really simple, so I could use a nudge in the right direction!
import {Register, State, Action} from 'meteor/meteorflux:meteorflux';
Register(() => {
switch (Action.type()) {
case 'USER_CLICKED':
console.info('Register: USER_CLICKED received');
State.set('clickCount', State.get('clickCount') + 1);
}
});
State.modify('clickCount', (state = 0) => {
console.info('State: clickCount');
return state;
});
Using other reactive variables such as Mongo collections makes sense, but how do we set our own global app state vars? This works, though the State.set
feels like it doesn't belong in this process. Is it possible to just have a state var clickCount
that gets incremented when the user clicks a button? I'd rather not use ReactiveDict
because it doesn't allow you to easily change one property in an object (and winds up destroying the object).