mediawiki.js: Add mw.track
authorOri Livneh <ori@wikimedia.org>
Thu, 5 Dec 2013 22:51:40 +0000 (14:51 -0800)
committerOri Livneh <ori@wikimedia.org>
Mon, 23 Dec 2013 22:52:15 +0000 (14:52 -0800)
commit873b60f194557a0d514d238c69e176cde8e71839
tree5a7b558c2f97d66e583164e8a71cae61a94f6f92
parentf62b53b4855f3e9a648f09e295c55e41bbf425b5
mediawiki.js: Add mw.track

`mw.track` implements a topic-based message broker / event bus for
JavaScript code. Its distinguishing characteristic is that subscribers are
called with each event that matches their topic filter, including any
events that fired before the subscriber registered. This allows code to be
instrumented to report performance data without having to know anything
about subscribers, and it makes it trivial to attach MediaWiki events to
any event logging system -- not just EventLogging, but also Google
Analytics, New Relic, etc., which is a compelling feature for third-party
users.

The implementation is ported from VisualEditor, where it was introduced in
change I29740fa7a and subsequently refined. I did not port
`ve.trackSubscribeAll`, since it is syntactic sugar for calling
`ve.trackSubscribe` with the empty string as a subscription. It made sense
to have a wrapper for VE, since registering a handler for all VE events is
a credible use-case, but it seems less legitimate if `track` is expanded
to the entire MediaWiki ecosystem.

Change-Id: I8c7af097e6a9b2781ba3d6625d1132b7788ce8da
resources/mediawiki/mediawiki.js