jenkins-bot has submitted this change and it was merged.
Change subject: ve.track: add topic-based analytic event subscription
......................................................................
ve.track: add topic-based analytic event subscription
Replace ve.trackRegisterHandler with two methods: ve.trackSubscribe and
ve.trackSubscribeAll. The former takes an additional string argument 'topic',
which specifies a string prefix on which to match event names. The callback is
only called on matching events. The latter, ve.trackSubscribeAll, binds a
handler to all track events, regardless of topic.
This patch simplifies argument-handling by eliminating variadic ve.track calls
in favor of a single object that encodes all event data. The loose coupling of
track event emitters and subscribers makes relying on unnamed positional
argument conventions brittle; property access works better.
Change-Id: I3b58ce0f48ad3c9b56fcaa9c2226cc79bbcd4051
(cherry picked from commit 495f247570a2303a9e40ad48238fe884bed91535)
---
M modules/ve/ve.track.js
1 file changed, 33 insertions(+), 14 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ve.track.js b/modules/ve/ve.track.js
index 4455530..c457fd8 100644
--- a/modules/ve/ve.track.js
+++ b/modules/ve/ve.track.js
@@ -18,31 +18,50 @@
* generic interface for routing these events to an analytics framework.
*
* @member ve
- * @param {string} name Event name
- * @param {Mixed...} [data] Data to log
+ * @param {string} topic Event name
+ * @param {Object} [data] Additional data describing the event, encoded
as an object
*/
- ve.track = function () {
- queue.push( { context: { timeStamp: ve.now() }, args: arguments
} );
+ ve.track = function ( topic, data ) {
+ queue.push( { topic: topic, timeStamp: ve.now(), data: data } );
callbacks.fire( queue );
};
/**
- * Register a handler for analytic events.
+ * Register a handler for subset of analytic events, specified by topic
*
* Handlers will be called once for each tracked event, including any
events that fired before the
* handler was registered; 'this' is set to a plain object with a
'timeStamp' property indicating
- * the exact time at which the event fired.
+ * the exact time at which the event fired, a string 'topic' property
naming the event, and a
+ * 'data' property which is an object of event-specific data. The event
topic and event data are
+ * also passed to the callback as the first and second arguments,
respectively.
+ *
+ * @member ve
+ * @param {string} topic Handle events whose name starts with this
string prefix
+ * @param {Function} callback Handler to call for each matching tracked
event
+ */
+ ve.trackSubscribe = function ( topic, callback ) {
+ var seen = 0;
+
+ callbacks.add( function ( queue ) {
+ var event;
+ for ( ; seen < queue.length; seen++ ) {
+ event = queue[ seen ];
+ if ( event.topic.indexOf( topic ) === 0 ) {
+ callback.call( event, event.topic,
event.data );
+ }
+ }
+ } );
+ };
+
+ /**
+ * Register a handler for all analytic events
+ *
+ * Like ve#trackSubscribe, but binds the callback to all events,
regardless of topic.
*
* @member ve
* @param {Function} callback
*/
- ve.trackRegisterHandler = function ( callback ) {
- var invocation, seen = 0;
- callbacks.add( function ( queue ) {
- for ( ; seen < queue.length; seen++ ) {
- invocation = queue[ seen ];
- callback.apply( invocation.context,
invocation.args );
- }
- } );
+ ve.trackSubscribeAll = function ( callback ) {
+ ve.trackSubscribe( '', callback );
};
}() );
--
To view, visit https://gerrit.wikimedia.org/r/90177
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3b58ce0f48ad3c9b56fcaa9c2226cc79bbcd4051
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: wmf/1.22wmf21
Gerrit-Owner: Jforrester <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits