goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 323 forks source link

Default behavior EmitChange in Store #614

Closed zazapeta closed 8 years ago

zazapeta commented 8 years ago

Hello,

I'm using altjs v0.17.1 I've noticed recently that if I change a state value in the store (see example below), an emit change is triggered automatically after processing the handler. I always thought, (and used it this way for the last year) that I needed to explicitly call this.emitChange(). This resulted in rendering my view twice, as it emitted emitChange twice. I could not find documentation about this behavior. Therefore I'm wondering if it's the normal behavior or is it a bug ? If it's the normal behavior, I think it should be specified in the documentation.

Thank you.

class MyStore{
  constructor() {
    this.foo = 'bar';
  }

  onFooBarChange(val) {
    this.foo = val;
    //EmitChange is automatically triggered 
  }
}
jdlehman commented 8 years ago

This is the normal behavior. You can return false from a store method to prevent emitting a change. this.emitChange is provided for use cases outside of the norm.