Cannot get static property to work in emberjs class using property bindings

I am trying to create a static property in an ember object (all instances should have the same property and respond when it changes). In my case, I have 4 different instances, if any of these instances changes the property refresh, I want all 4 instances to respond to it.

I found that binding refreshis only done for the current instance in which I want it to be done for the whole instance if it is a static property.

        enabled : function() {
           ...
        }.property('refresh'), <----- this only executes for the current instance


        selectionChanged : function() { 
            ...
            this.incrementProperty('refresh');
        }.observes('selection')

I tried to create a property refreshusing mixin

    var AbstractControlMixin = Ember.Mixin.create({
        refresh : 0
    });

    var AbstractControl = Ember.Object.extend(AbstractControlMixin,{
       ...
    });

using the re-open method

var AbstractControl = Ember.Object.extend({
    ...
});

AbstractControl.reopen({
            refresh : 0
});

but does not work.

+4
source share
1

, , . , , , , , .

var klass = Em.Object.extend({
  name:'',
  refresh:{
    value:0
  },
  changed: function(){
    console.log('refresh ' + this.get('name'));
  }.observes('refresh.value')
});

var k1 = klass.create({name:'k1'});
var k2 = klass.create({name:'k2'});

k1.incrementProperty('refresh.value'); // this will fire changed for all instances

http://emberjs.jsbin.com/yucupofosu/1/edit?html,js,output

+6

Source: https://habr.com/ru/post/1570096/


All Articles