meteorflux icon indicating copy to clipboard operation
meteorflux copied to clipboard

How to actually set state?

Open ffxsam opened this issue 8 years ago • 1 comments

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).

ffxsam avatar Jan 30 '16 22:01 ffxsam