Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Ember.js Object observer equivalent to ES6 Harmony Object.observe?

Looking at the new observe ES6 featues inside object, I was wondering whether Ember and ES6 are equivalent or different? Can we use the Watchjs polyfill safely with ember?

like image 665
Ankur Agarwal Avatar asked Oct 06 '22 21:10

Ankur Agarwal


1 Answers

Looking at the new observe ES6 featues inside object, I was wondering whether Ember and ES6 are equivalent or different?

Most definitely different. EmberJs has it own system, where every "model" (object whose properties may be observed), is wrapped in an instance of Ember.Object. The Ember.Object base class provides all the mechanisms for listening for property changes. In order to use them, all one needs to do is .get() and .set() to access and mutate its properties.

Can we use the Watchjs polyfill safely with ember?

I have not tried this before, but I would caution against it, as my educated guess is that it will not work. This is because, as mentioned above, Ember relies on getters and setters to listen for changes on object properties, not Object.observe. So even if you use this WatchJs (or any other polyfill), EmberJs app would be oblivious to the changes, because Ember.Object does not understand or use this at the moment.

like image 90
bojangle Avatar answered Oct 10 '22 02:10

bojangle