最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ember.Instrumentation API example - Stack Overflow

programmeradmin1浏览0评论

I have been going through this post regarding newly added features in EmberJS. One of them being Ember.Instrumentation, can anyone explain where do we use it, if possible with an example...Thanks

I have been going through this post regarding newly added features in EmberJS. One of them being Ember.Instrumentation, can anyone explain where do we use it, if possible with an example...Thanks

Share Improve this question asked Oct 16, 2012 at 17:49 Mudassir AliMudassir Ali 8,0414 gold badges33 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Why

Instrumentation in general is a way to measure performance and other metrics in your app by subscribing to namespaced listeners. It can also be useful for debugging.

Example

I can't take credit for making this fiddle, I only saw it last night at the NYC ember.js meetup, but this should provide some context:

http://jsfiddle/2Pn3f/6/

In my attempt to figure out who presented this, I could only find his meetup profile: http://www.meetup./EmberJS-NYC/members/6706336/

To see the magic happen, open your console and start marking students as 'here.'

See the StudentView near the top and Em.Subscribe at the bottom.

// In a view
Em.instrument("student.here", this.get('content'), function() {
    //mark student as in attendance
    this.set('inAttendance', !this.get('inAttendance'));
  }, this);
},

...

Em.subscribe('*', {
  ts: null,
  before: function(name, timestamp, payload) {
    ts = timestamp;
    //console.log('    before: ', name, JSON.stringify(payload));
    //return 'HelloFromThePast';
  },
  after: function(name, timestamp, payload, beforeRet) {
    //log metrics
    //record analytics
    //profile app
    console.log('instrument: ', name, JSON.stringify(payload), beforeRet, timestamp - ts);
  }
});

Side note

What's even cooler is that you can subscribe to ember's use of instrumentation by using the wildcard.

http://jsfiddle/dmazza/sUvdg/

Documentation

See the documentation for details: http://emberjs./api/classes/Ember.Instrumentation.html

发布评论

评论列表(0)

  1. 暂无评论