middleware/mw.service.init.js
function reactHandler(reactData) {
        return function (eventData) {

            // handler should always be run asynchronously
            setTimeout(function () {
                var payload = eventData.payload;
                var inputData = payload.inputData;
                var reactor = reactors[reactData.type + '.reactor'];
                var matchesCriteria = objUtils.matchesCriteria(payload.data, reactData.criteria);
                var fieldMissing = reactData.onFieldChange && reactData.onFieldChange.length &&
                    _.isEmpty(fakeblock.filter.getFieldsFromObj(inputData, reactData.onFieldChange));

                if (!reactor) {
                    log.info('reactHandler does not exist: ' + JSON.stringify(reactData));
                }

                if (!reactor || !matchesCriteria || fieldMissing) {
                    //deferred.resolve();
                    return;
                }

                Q.fcall(function () {
                    reactor.react({
                        caller:         payload.caller,
                        inputData:      inputData,
                        data:           payload.data,
                        context:        payload.context,
                        reactData:      reactData,
                        resourceName:   eventData.name.resource,
                        methodName:     eventData.name.method
                    });
                }).catch(log.error);
            });
        };
    }
function reactHandler(reactData) {
        return function (eventData) {

            // handler should always be run asynchronously
            setTimeout(function () {
                var payload = eventData.payload;
                var inputData = payload.inputData;
                var reactor = reactors[reactData.type + '.reactor'];
                var matchesCriteria = objUtils.matchesCriteria(payload.data, reactData.criteria);
                var fieldMissing = reactData.onFieldChange && reactData.onFieldChange.length &&
                    _.isEmpty(fakeblock.filter.getFieldsFromObj(inputData, reactData.onFieldChange));

                if (!reactor) {
                    log.info('reactHandler does not exist: ' + JSON.stringify(reactData));
                }

                if (!reactor || !matchesCriteria || fieldMissing) {
                    //deferred.resolve();
                    return;
                }

                Q.fcall(function () {
                    reactor.react({
                        caller:         payload.caller,
                        inputData:      inputData,
                        data:           payload.data,
                        context:        payload.context,
                        reactData:      reactData,
                        resourceName:   eventData.name.resource,
                        methodName:     eventData.name.method
                    });
                }).catch(log.error);
            });
        };
    }
function reactHandler ( reactData ) { return function ( eventData ) { // handler should always be run asynchronously setTimeout ( function ( ) { var payload = eventData . payload ; var inputData = payload . inputData ; var reactor = reactors [ reactData . type + '.reactor' ] ; var matchesCriteria = objUtils . matchesCriteria ( payload . data , reactData . criteria ) ; var fieldMissing = reactData . onFieldChange && reactData . onFieldChange . length && _ . isEmpty ( fakeblock . filter . getFieldsFromObj ( inputData , reactData . onFieldChange ) ) ; if ( ! reactor ) { log . info ( 'reactHandler does not exist: ' + JSON . stringify ( reactData ) ) ; } if ( ! reactor || ! matchesCriteria || fieldMissing ) { //deferred.resolve(); return ; } Q . fcall ( function ( ) { reactor . react ( { caller : payload . caller , inputData : inputData , data : payload . data , context : payload . context , reactData : reactData , resourceName : eventData . name . resource , methodName : eventData . name . method } ) ; } ) . catch ( log . error ) ; } ) ; } ; }
Get handler for a react event
@param reactData
@returns {Function}
Get handler for a react event