Ember.Instrumentation API示例

Mud*_*Ali 6 javascript ember.js

关于EmberJS中新添加的功能,我一直在阅读这篇文章.其中一个是Ember.Instrumentation,任何人都可以解释我们在哪里使用它,如果可能的话,举个例子......谢谢

dmz*_*zza 9

为什么

一般而言,Instrumentation是一种通过订阅命名空间侦听器来衡量应用程序中的性能和其他指标的方法.它也可用于调试.

我不能因为制作这个小提琴而受到赞扬,我昨晚只在NYC ember.js聚会上看到它,但这应该提供一些背景信息:

http://jsfiddle.net/2Pn3f/6/

在我想弄清楚是谁的时候,我只能找到他的聚会资料:http://www.meetup.com/EmberJS-NYC/members/6706336/

要看到魔力发生,打开你的控制台,开始将学生标记为"在这里".

查看顶部附近的StudentView和底部的Em.Subscribe.

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

...

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);
  }
});
Run Code Online (Sandbox Code Playgroud)

边注

甚至更酷的是你可以使用通配符订阅ember使用的仪器.

http://jsfiddle.net/dmazza/sUvdg/

文档

有关详细信息,请参阅文档:http://emberjs.com/api/classes/Ember.Instrumentation.html