cibernox / cibernox/ember-cpm

Proper support for composable properties

Open
#96 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
276
Forks
31
PR merge metrics
No merged PRs in 30d

Description

This is a long term plan for adding proper support to composable computed properties in a more efficient way.

There was a proposal that ended in a no-go by the core team. You can checkout [this commit](https://github.com/emberjs/ember.js/tree/ea687fe1d173c7499bfb5f3e1d0b6360e0d8701c) and search for `Ember.FEATURES.isEnabled('composable-computed-properties')` in the source code to see the original implementation.

The key difference with the current implementation is in the way computed properties that receive other computed properties subscribe to changes.
- In this repo when a macro receives another macro as arguments, it inspects the dependencies of those computed properties and sets them as dependencies of the new macros. See https://github.com/cibernox/ember-cpm/blob/master/addon/utils.js#L38
- The original approach is more efficient. Whenever an anonymous macros is created, it is registered in the global Ember namespace with a unique name (its `guid`). Therefore, when a macro receives a computed macros to compose the only thing it has to do is watch that key in the global Ember space.

This approach is more efficient since it sets up much less watches and also simplifies the code of the macros considerably. Also, should be more resilent to changes in ember itself, since it does not need to use private APIs of the computed properties.

The downside of this approach is that it can't be achieved completely from the plugins (I think), since it requires some changes in the guts of ember itself, by example in `defineProperty` (see [this](https://github.com/emberjs/ember.js/blob/ea687fe1d173c7499bfb5f3e1d0b6360e0d8701c/packages/ember-metal/lib/properties.js#L120-L124)).

Therefore, to get this approach working a bit of bureaucracy will be necessary, either convince the core team to allow anonymous computed properties to be registered in the global namespace, or to provide a few extension points in key points of the core to allow to customize how thinks like defineProperty works.

Eventually the ultimate goal could be to offer a composable-compatible version to every macro built in ember to, eventually in ember 2.0, remove all computed properties from the core of ember (and therefore slim it of non superfluos) and let them live here.

/cc @TrueNorth @hjdivad

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.