Playing with Ember.Object.reopen (), why do I have these results?

I tried to answer this question: emberjs: add routes after application initialization ()

I started playing with Ember.Object.reopen () to understand how this works, and maybe find a way to answer the previous question.

I am a little puzzled and don't understand the behavior of this code:

jsfiddle: http://jsfiddle.net/Sly7/FpJwT/

<script type="text/x-handlebars">
  <div>{{App.myObj.value}}</div>
  <div>{{App.myObj2.value}}</div>
  <div>{{App.myObj3.value}}</div>
</script>
App = Em.Application.create({});

App.MyObject = Em.Object.extend({value: 'initial'});

App.set('myObj', App.MyObject.create());

Em.run.later(function(){
  App.get('myObj').reopen({
    value: "reopenOnInstance"        
  }); // the template is not updated, 'initial' is still diplayed, but
  console.log(App.get('myObj').get('value')); // print 'reopenOnInstance'

  App.MyObject.reopen({
    value: "reopenOnClass"      
  });
  App.set('myObj2',App.MyObject.create()); // the template is updated and 
  console.log(App.get('myObj2').get('value')); //print 'reopenOnClass'

  App.myObj3 = App.MyObject.create(); // the template is not updated but
  console.log(App.myObj3.get('value')); // print 'reopenOnClass'

  Em.run.later(function(){
    App.get('myObj').set('value', "setWithSetter"); // the template is updated and
    console.log(App.get('myObj').get('value')); // print 'setWithSetter'

    App.get('myObj2').set('value', "setWithSetter"); // the template is updated and
    console.log(App.get('myObj2').get('value')); // print 'setWithSetter'

    App.myObj3.set('value', "setWithSetter"); // the template is not updated but
    console.log(App.myObj3.get('value')); // print 'setWithSetter'

  }, 2000);
},2000);

If someone can explain what is happening, especially why the templates are sometimes not updated, sometimes updated, and also what is the difference between a call reopenin a class, a call to it and an instance.

+5
source share
1 answer

Not 100% sure, but I will try to answer your questions.

"myObj3". ember getter/setter ( , / , - ). , , , , . , Mutable, pushObject, .

" ". , , , . , . , "get", ember mixin . , mixin ; "return" foo '+ this._super() " , " foo initial "(, , ). mixin , , - ( "get" ). , "set" .

: "getPath" "get", . , App.getPath('myObj2.value'), . "setPath".

: , ( ), ember ui , set myObj3.

EDIT: ember , ( ). , .

+5

All Articles