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

Updating a value from a hash trigger observer on the whole hash #298

Open
cbou opened this issue Apr 24, 2017 · 1 comment
Open

Updating a value from a hash trigger observer on the whole hash #298

cbou opened this issue Apr 24, 2017 · 1 comment

Comments

@cbou
Copy link

cbou commented Apr 24, 2017

I observe a particular property of a hash. When I update another property of this hash, then the observer of the first property is triggered. It seems wrong to me.

Here is a sample code:

components/test-macro.js

import Ember from 'ember';
import {hash} from 'ember-awesome-macros';

export default Ember.Component.extend({
	foo: hash({
		prop1: 'prop1',
		prop2: 'prop2'
	}),
	
	prop1: 'hello',
	prop2: 'world',
	
	fooObserver: Ember.observer('foo', function() {
		console.log('Hello foo!');
	}),
	
	prop1Observer: Ember.observer('foo.prop1', function() {
		console.log('Hello foo.prop1!');
	}),
	
	prop2Observer: Ember.observer('foo.prop2', function() {
		console.log('Hello foo.prop2!');
	}),
	
	actions: {
		updateProp1: function() {
			this.set('prop1', 'bonjour');
		}
	}
	
});

templates/components/test-macro.js

{{foo.prop1}} {{foo.prop2}}

<button {{action 'updateProp1'}}>Update prop1</button>

When I click on Update prop1 the console prints:

Hello foo.prop1!
Hello foo.prop2!
Hello foo!

I would actually only expect prop1

@kellyselden
Copy link
Owner

I'm not sure how to solve this, since I don't have reference to the previously created object. The macro creates a new one every time.

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