Skip to content

Instantly share code, notes, and snippets.

@hjdivad
Created October 24, 2013 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjdivad/7131858 to your computer and use it in GitHub Desktop.
Save hjdivad/7131858 to your computer and use it in GitHub Desktop.

Ember.select Slide

  • s/Ember.select/Ember.Select i think.

This slide is damn funny ^_^

Array Computed Slide

Nothing to add to the slide, but a minor note to keep in mind: there is another difference. arrayComputed adds observers to keep refs up to date. So eg

var array = obj.get('someArrayComputedProperty');

// later modify dependency
// array is kept up to date

It would be nice to not have to do this: would like to make the reduceComputed stuff support lazy, but it's not there yet.

More Things to Mention / Keep in Mind

  • callbacks get given changeMeta with many useful properties, like index of item that changed

  • callbacks also given instanceMeta, a scratchpad that is 〈instance, property〉 specific where you can keep track of things for more involved properties. For example, intersect keeps track of a count of items seen per dependent array to know when an item belongs in the intersection and when it does not.

  • It is possible to depend on properties of items in arrays. This will still give callbacks the right index. This is actually non-trivial when you think about it (it's also not as performant as doing non-property stuff, all other things equal).

  • This feature is actively worked on: check release notes. Some newer stuff is still experimental and behind feature flags, but for instance you can depend on multiple item properties with a brace syntax, as in

    // depends on feature propertyBraceExpansion
    
    Ember.Object.extend({
      items: [{ propA: 'a', propB: 'b', propC: 'c'},
              { propA: 'a2', propB: 'b2', propC: 'c2' }],
    
      // if you change either `propA` on something in `items`, or `propB`, but not
      // `propC`, the item will be removed and readded to `computed`.  When it is
      // removed you will be passed the previous value.
      computed: Ember.reduceComputed('items.@each.{propA,propB}', {
        addedItem: addedItemCallback,
        removedItem: removedItemCallback
      });
    })
  • maybe give a shout-out to ember-cpm, a great place to contribute macros.

  • also a shout-out to ember-enumerology which is awesome in its own right and has been upgraded to use reduce computeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment