我一直在浏览关于EmberJS中新增功能的this帖子。其中一个是Ember.Instrumentation,如果可能的话,有没有人能解释一下我们在哪里使用example...Thanks呢?
发布于 2012-10-27 04:39:32
为什么
通常,插装是一种通过订阅命名空间侦听器来测量应用程序中的性能和其他指标的方法。它对调试也很有用。
示例
我不能相信我做了这个小提琴,我只是在昨晚的纽约市ember.js会议上看到它,但这应该提供一些背景:
http://jsfiddle.net/2Pn3f/6/
在我试图找出是谁展示了这个的过程中,我只能找到他的meetup个人资料:http://www.meetup.com/EmberJS-NYC/members/6706336/
要想看到奇迹的发生,打开你的控制台,开始将学生标记为“here.‘”。
查看靠近顶部的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);
},..。
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);
}
});旁注
更酷的是,您可以通过使用通配符订阅ember对插装的使用。
http://jsfiddle.net/dmazza/sUvdg/
文档
有关详细信息,请参阅文档:http://emberjs.com/api/classes/Ember.Instrumentation.html
https://stackoverflow.com/questions/12920543
复制相似问题