Why does a component class need to be reopened to indicate positional parameters?

When specifying a positional parameter for a component class in ember you need to open the class again (for example, below) for it to work, you cannot include it in the initial declaration (at least from what I saw in the examples and my own experience) .

import Ember from 'ember'; const component = Ember.Component.extend({ }); component.reopenClass({ positionalParams: ['post'], }); export default component; 

If you do this in a single declaration (e.g. below), it will not work

 import Ember from 'ember'; export default Ember.Component.extend({ positionalParams: ['post'], }); 

Questions

  • Was this something missing from the design process? Or was it intentional (perhaps to discourage use)?
  • Is it because it's some kind of class attribute? Is there a way to specify class attributes in a class declaration?

It just seems rude that I cannot make it part of the same expression and must assign the class to a variable, open it again, and then finally export it.


Version

  • ember.js @ 2.2
+5
source share
1 answer

Is it because it's some kind of class attribute?

It. The reopenClass and extend methods do not do the same.

  • Properties passed to reopenClass are placed in the constructor of the class itself:

     MyClass = Ember.Object.extend({}); MyClass.reopenClass({ foo: 42 }); obj = MyClass.create(); console.log(obj.foo); // undefined console.log(MyClass.foo); // 42 console.log(obj.constructor.foo); // 42 
  • On the other hand, properties passed to extend are available (*) for instances:

     MyClass = Ember.Object.extend({ foo: 42 }); obj = MyClass.create(); console.log(obj.foo); // 42 console.log(MyClass.foo); // undefined console.log(obj.constructor.foo); // undefined 

(*) I do not know if they are copied or made part of the prototype chain.

+2
source

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


All Articles