Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a computed property that depends on a global class attribute?
    primarykey
    data
    text
    <p>I wanna create a property that depends on a global attribute:</p> <pre><code>App.Test= Em.Object.extend(); App.Test.reopenClass({ all: Em.A() }); App.Other = Em.object.extend({ stuff: function() { return "calculated stuff from this.get('foo') and App.Test.all"; }.property('foo', 'App.Test.all.@each.bar') }); </code></pre> <p>As a workarround I could create a observer and always set a dummy property with a new random value to trigger the property change, but is there a better way to do this?</p> <p>I need this for some caching. I've a really crazy, and single threaded backend. So I write my own Model classes. So I try to reimplement a bit of the logic in the client for a better caching.</p> <p>Ive an Item class (App.Item) and another class where each instance has a calculated reduced list of Items.</p> <pre><code>App.Model = Em.Object.extend({ }); App.Model.reopenClass({ all: Em.A(), load: function(hash) { return this.get('all').pushObject(this.create(hash)); } }); App.Item = App.Model.extend({ }); App.List = App.Model.extend({ loadedInitItems: false, items: function() { if(!this.get('loadedInitItems')) { this.set('loadedInitItems', true); Backend.call('thelist', function(item) { App.Item.load(this); }); } return App.Item.all.filter(function(item) { // heavy filter stuff, depends on a lot of propertys on the current list instance }); }.property('someprops', 'App.Item.all.@each.foo') }); </code></pre> <p>Backend.call represents some AJAX stuff</p> <p>the point is, that now any item could change so that the filter will return something diffrent. And there are other places om the application, where the user can add Items. I dont want to call the backend again, because its very slow! And I know that the backend will not modify the list! So I wanna cache it.</p> <p>This is just a reduced example of my use case, but I think've described the point. In reallity I have this dozend of times, with over 25000 objects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload