Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/68140


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, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging 
refs/changes/40/68140/1

diff --git a/modules/ext.eventLogging.core.js b/modules/ext.eventLogging.core.js
index fe18667..7ce5d92 100644
--- a/modules/ext.eventLogging.core.js
+++ b/modules/ext.eventLogging.core.js
@@ -206,15 +206,17 @@
 
 
                /**
-                * 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 ) {
+               prepare: function ( schemaName, event ) {
                        var schema = self.schemas[ schemaName ];
 
                        if ( schema === undefined ) {
@@ -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: newchange
Gerrit-Change-Id: I86cc10854b0058b3ae9623c7c47d2c0824919193
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to