mediawiki.base: Document mw.track debug console snippet

Change-Id: I95db3bd17870c962128515d2840af76dc07d79b9
This commit is contained in:
Timo Tijhof 2022-07-11 15:13:08 -07:00
parent f00cd03580
commit 4dc48a6c17

View file

@ -336,8 +336,8 @@ var trackHandlers = [];
* well-defined purpose. * well-defined purpose.
* *
* Data handlers are registered via `mw.trackSubscribe`, and receive the full set of * Data handlers are registered via `mw.trackSubscribe`, and receive the full set of
* events that match their subscription, including those that fired before the handler was * events that match their subscription, including buffered events that fired before the handler
* bound. * was subscribed.
* *
* @param {string} topic Topic name * @param {string} topic Topic name
* @param {Object|number|string} [data] Data describing the event. * @param {Object|number|string} [data] Data describing the event.
@ -350,10 +350,18 @@ mw.track = function ( topic, data ) {
/** /**
* Register a handler for subset of analytic events, specified by topic. * 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 * Handlers will be called once for each tracked event, including for any buffered events that
* handler was registered; 'this' is set to a plain object with a topic' property naming the event, and a * fired before the handler was subscribed. The callback is passed a `topic` string, and optional
* 'data' property which is an object of event-specific data. The event topic and event data are * `data` event object. The `this` value for the callback is a plain object with `topic` and
* also passed to the callback as the first and second arguments, respectively. * `data` properties set to those same values.
*
* Example to monitor all topics for debugging:
*
* mw.trackSubscribe( '', console.log );
*
* Example to subscribe to any of `foo.*`, e.g. both `foo.bar` and `foo.quux`:
*
* mw.trackSubscribe( 'foo.', console.log );
* *
* @param {string} topic Handle events whose name starts with this string prefix * @param {string} topic Handle events whose name starts with this string prefix
* @param {Function} callback Handler to call for each matching tracked event * @param {Function} callback Handler to call for each matching tracked event