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
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.
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.net/2Pn3f/6/
In my attempt to figure out who presented this, I could only find his meetup profile: http://www.meetup.com/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);
}
});
What's even cooler is that you can subscribe to ember's use of instrumentation by using the wildcard.
http://jsfiddle.net/dmazza/sUvdg/
See the documentation for details: http://emberjs.com/api/classes/Ember.Instrumentation.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With