published properties not changed on creation?

If I create a kind with published properties, and corresponding Changed events:

enyo.kind({
	name:'thing_one',
	published:{
		thing:1
	},
	thingChanged:function(oldThing){
		console.log('Thing Changed');
	}
});
And then I create those objects with those changed properties

components: [{
	name:'thing_two',
	kind:"thing_one",
	thing:2
}]
it is not firing those change events. I understand that the documentation says that changing the properties directly would not fire the events, but I thought it was talking more about this.$.thing_two = 2. Is there a way I can get these change events to fire?

What I've done temporarily is override create() and put in
if(this.thing != 1)thingChanged(1);

Is there a cleaner option?

Comments

  • in thing_one, add:
    create: function(){
             this.inherited(arguments);
             this.thingChanged();
    }
  • Instead of setting the "thing" property to 2 in your components block, you can do it in the create() function (or a function called by create()) which will call the thingChanged() function:
    enyo.kind({
        name: "App",
        components: [{
    	    name:'thing_two',
    	    kind:"thing_one"
        }],
        
        create: function() {
            this.inherited(arguments);
            this.$.thing_two.set("thing", 2);
        }
    });
  • Okay, it looks like psarin is recommending the same concept as what I did. psarin, the difference with what I said I was using for my temporary solution is that I'm testing to see if the value is not the default. if I just call thingChanged(), will it do that automatically for me?
  • edited June 2014
    @trex005‌ I'm assuming you're using the latest enyo master (2.5 pre-release) as we made some changes to not automatically call a lot of change handlers upon initialization to improve efficiency and reduce unnecessary execution. The change handler will automatically be called when the new value is different than the existing value. If you manually call the change handler then you've bypassed that check, but you can still check yourself by comparing the first parameter (the old value) with the current value instead of hard-coding i.e.
    
    thingChanged: function(inOldValue) {
        if (inOldValue !== this.thing) { // perform operations only when value has changed }
    }
    
Sign In or Register to comment.