javascript - Ember.Instrumentation API example - Stack Overflow

I have been going through this post regarding newly added features in EmberJS. One of them being Ember.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745342885a4623409.html

相关推荐

  • javascript - Ember.Instrumentation API example - Stack Overflow

    I have been going through this post regarding newly added features in EmberJS. One of them being Ember.

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信