jenkins-bot has submitted this change and it was merged.
Change subject: 'encapsulate' => 'prepare'; computed properties
......................................................................
'encapsulate' => 'prepare'; computed properties
This change set adds the notion of 'computed' properties. If an event
property's value is a function (or if the value is missing and its default is a
function), EventLogging will invoke it with the entire event as the context
object and use the return value as the value for that property.
Change-Id: I86cc10854b0058b3ae9623c7c47d2c0824919193
---
M modules/ext.eventLogging.core.js
1 file changed, 13 insertions(+), 6 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ext.eventLogging.core.js b/modules/ext.eventLogging.core.js
index fe18667..a918a1a 100644
--- a/modules/ext.eventLogging.core.js
+++ b/modules/ext.eventLogging.core.js
@@ -206,16 +206,18 @@
/**
- * Takes an event object and puts it inside a generic wrapper
- * object that contains generic metadata about the event.
+ * Prepares an event for dispatch by filling-in defaults for any
+ * missing properties, evaluating any computed properties, and
+ * then encapsulating the result in a generic wrapper object
+ * that contains metadata about the event.
*
- * @method encapsulate
+ * @method prepare
* @param {String} schemaName Canonical schema name.
* @param {Object} event Event instance.
* @return {Object} Encapsulated event.
*/
- encapsulate: function ( schemaName, event ) {
- var schema = self.schemas[ schemaName ];
+ prepare: function ( schemaName, event ) {
+ var prop, schema = self.schemas[ schemaName ];
if ( schema === undefined ) {
self.warn( 'Got event with unknown schema "' +
schemaName + '"' );
@@ -223,6 +225,11 @@
}
event = $.extend( true, {}, schema.defaults, event );
+ for ( prop in event ) {
+ if ( typeof event[ prop ] === 'function' ) {
+ event[ prop ] = event[ prop ].call(
event );
+ }
+ }
return {
event : event,
@@ -277,7 +284,7 @@
* @return {jQuery.Promise} jQuery Promise object for the
logging call
*/
logEvent: function ( schemaName, eventInstance ) {
- return self.dispatch( self.encapsulate( schemaName,
eventInstance ) );
+ return self.dispatch( self.prepare( schemaName,
eventInstance ) );
}
};
--
To view, visit https://gerrit.wikimedia.org/r/68140
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I86cc10854b0058b3ae9623c7c47d2c0824919193
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: DarTar <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits