Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change:a.x fired, while no change:a firing? #257

Open
claydodo opened this issue Dec 8, 2017 · 2 comments
Open

change:a.x fired, while no change:a firing? #257

claydodo opened this issue Dec 8, 2017 · 2 comments

Comments

@claydodo
Copy link

claydodo commented Dec 8, 2017

I'm using ampersand-state 4.9.1 and have a State defined like this:

var MyState = State.extend({
    props: {
        a: 'state'
    },
    
    setA: function(x, y) {
        this.a.set({x: x, y: y});
    }
})

where a is always an instance of A:

var A = State.extend({
    props: {
        x: 'number',
        y: 'number'
    }
})

When using MyState's instance someObj.setA(3, 5), etc, I find that the following events are fired:

  • change:a.x
  • change:a.y
  • change (someObj's own change event)

But there's no change.a fired, which is desired. Because in my app I want to observe MyState's change:a to handle the changes of x and y at the same time, instead of observing change:a.x and change:a.y (which suites other scenarios, though) as independent events.

Is this an issue worth consideration? Or am I using sub-states in a wrong way?

@dhritzkiv
Copy link
Member

I think it's definitely worth considering the behaviour a little more closely, especially since someObj fires a change event for itself.

When looking at it like this, I think there's a strong case for emitting "change:a"

|||- x (change event fired)
|||- y (change event fired)
||- a (change event NOT fired)
|- someObj (change event fired)

Presently, I believe change:a is only fired when the actual reference to the state instance is changed:

someObj.a = new A(); //this should emit a `change:a` event

Out of curiosity, what happens when you set someObj.a.parent = someObj? Does that have any effect?

@claydodo
Copy link
Author

I tried the parent stuff, but there's no effect.

I'm using some other approach to overcome this issue for now, and waiting for the upgrade of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants