API Docs for: 1.0 pre
Show:

Ember.Instrumentation Class

The purpose of the Ember Instrumentation module is to provide efficient, general-purpose instrumentation for Ember.

Subscribe to a listener by using Ember.subscribe:

Ember.subscribe("render", {
  before: function(name, timestamp, payload) {

  },

  after: function(name, timestamp, payload) {

  }
});

If you return a value from the before callback, that same value will be passed as a fourth parameter to the after callback.

Instrument a block of code by using Ember.instrument:

Ember.instrument("render.handlebars", payload, function() {
  // rendering logic
}, binding);

Event names passed to Ember.instrument are namespaced by periods, from more general to more specific. Subscribers can listen for events by whatever level of granularity they are interested in.

In the above example, the event is render.handlebars, and the subscriber listened for all events beginning with render. It would receive callbacks for events named render, render.handlebars, render.container, or even render.handlebars.layout.

Methods

(
  • pattern
  • callback
)
private

Expands pattern, invoking callback for each expansion.

The only pattern supported is brace-expansion, anything else will be passed once to callback directly. Brace expansion can only appear at the end of a pattern, for an example see the last call below.

Example

function echo(arg){ console.log(arg); }

Ember.expandProperties('foo.bar', echo);        //=> 'foo.bar'
Ember.expandProperties('{foo,bar}', echo);      //=> 'foo', 'bar'
Ember.expandProperties('foo.{bar,baz}', echo);  //=> 'foo.bar', 'foo.baz'
Ember.expandProperties('{foo,bar}.baz', echo);  //=> '{foo,bar}.baz'

Parameters:

  • pattern String

    The property pattern to expand.

  • callback Function

    The callback to invoke. It is invoked once per expansion, and is passed the expansion.

getProperties

(
  • obj
  • list
)
Hash

To get multiple properties at once, call Ember.getProperties with an object followed by a list of strings or an array:

Ember.getProperties(record, 'firstName', 'lastName', 'zipCode');
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }

is equivalent to:

Ember.getProperties(record, ['firstName', 'lastName', 'zipCode']);
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }

Parameters:

  • obj Object
  • list String... | Array

    of keys to get

Returns:

Hash:

instrument

(
  • [name]
  • payload
  • callback
  • binding
)

Notifies event's subscribers, calls before and after hooks.

Parameters:

  • [name] String optional

    Namespaced event name.

  • payload Object
  • callback Function

    Function that you're instrumenting.

  • binding Object

    Context that instrument function is called with.

reset

()

Resets Ember.Instrumentation by flushing list of subscribers.

subscribe

(
  • [pattern]
  • [object]
)
Subscriber

Subscribes to a particular event or instrumented block of code.

Parameters:

  • [pattern] String optional

    Namespaced event name.

  • [object] Object optional

    Before and After hooks.

Returns:

Subscriber:

unsubscribe

(
  • [subscriber]
)

Unsubscribes from a particular event or instrumented block of code.

Parameters:

  • [subscriber] Object optional