Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Porting MobX ideas to Ember.js - dependency-less properties?

$
0
0

@drogus wrote:

Recently I've read a lot about a new observable library written initially for ReactJS. From what I see on the surface it doesn't differ from what Ember.js offers a lot apart from one thing - properties don't need dependencies. For me this is a huge deal, because dependencies on properties are one of the worst parts of Ember.js in my opinion. A few reasons on top of my head:

  • they may be hard to understand for beginners (I've seen confusion on this several times)
  • a typo in a dependency may cause bugs that are hard to find, it will usually break only when a value changes after the initial page load
  • dependencies are just boilerplate
  • depending on nested collections is not possible without workarounds at the moment

As far as I understand how MobX works, dependencies are calculated on runtime - when a property is calculated, each lookup is registered and added to dependencies. This is neat and I think it may be actually faster than specifying dependencies by hand. Let's consider a following property:

Ember.computed('useFoo', 'foo', function() {
  if(this.get('useFoo')) {
    return this.get('foo');
  } else {
    return this.complicatedAndSlowComputation();
  }
});

Currently in Ember.js, when foo changes, the property will be recomputed even if useFoo is set to false. If Ember.js worked more like MobX and useFoo was set to false, only useFoo property would be registered as a dependency (because foo wouldn't be reached).

I'm wondering if a similar model could be introduced to Ember.js? My limited knowledge of Ember's observable code tells me that it could be possible, but I'm not really sure about that.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles