Deep watch arbitriary JSON keys with computed properties in Ember


#1

I have a use case where a Model has a JSON attribute used for arbitrary configurations: configuration: DS.attr().

I have a configurationService (initialized in every component/route/controller/…) with computed properties for easily retrieving this configurations throughout the application

Since the JSON configurations are quite large & have variable depth I can’t have a computed property for every single one.

Unfortunately, being the Service a singleton computed properties don’t detect the changes in the JSON keys (a.k.a. deep watch). I there a way to force deep watching a JSON attribute?

Example: I have the following computed property in my service:

profile: Ember.computed('configuration.profile', function() {
  return this.get('configuration.profile');
});

Considering the configuration object was: {configuration: {profile: {show_birthday: false}}}, if I somehow change show_birthday to true, it won’t be detected

  • Note: I considered https://github.com/lytics/ember-data-model-fragments but discarded it since it’s too verbose, the issue is that our configuration object can become quite large and deep, dynamic & unpredictable
  • I tried computed.alias as well with no success.

Any hints or alternatives would be appreciated :slight_smile:


#2

Hmm, how are you setting it? Try using Ember.set instead.