src/parse-mockdb.js
function runHook(className, hookType, data) {
  let hook = getHook(className, hookType);
  if (hook) {
    const hydrate = (rawData) => {
      const modelData = Object.assign({}, rawData, { className });
      const modelJSON = _.mapValues(modelData,
        // Convert dates into JSON loadable representations
        value => ((value instanceof Date) ? value.toJSON() : value)
      );
      return Parse.Object.fromJSON(modelJSON);
    };
    const model = hydrate(data, className);
    hook = hook.bind(model);

    const collection = getCollection(className);
    let original;
    if (collection[model.id]) {
      original = hydrate(collection[model.id]);
    }
    // TODO Stub out Parse.Cloud.useMasterKey() so that we can report the correct 'master'
    // value here.
    return hook(makeRequestObject(original, model, false)).then((beforeSaveOverrideValue) => {
      debugPrint('HOOK', { beforeSaveOverrideValue });

      // Unlike BeforeDeleteResponse, BeforeSaveResponse might specify
      let objectToProceedWith = model;
      if (hookType === 'beforeSave' && beforeSaveOverrideValue) {
        objectToProceedWith = beforeSaveOverrideValue.toJSON();
      }

      return Parse.Promise.as(objectToProceedWith);
    });
  }
  return Parse.Promise.as(data);
}
function runHook(className, hookType, data) {
  let hook = getHook(className, hookType);
  if (hook) {
    const hydrate = (rawData) => {
      const modelData = Object.assign({}, rawData, { className });
      const modelJSON = _.mapValues(modelData,
        // Convert dates into JSON loadable representations
        value => ((value instanceof Date) ? value.toJSON() : value)
      );
      return Parse.Object.fromJSON(modelJSON);
    };
    const model = hydrate(data, className);
    hook = hook.bind(model);

    const collection = getCollection(className);
    let original;
    if (collection[model.id]) {
      original = hydrate(collection[model.id]);
    }
    // TODO Stub out Parse.Cloud.useMasterKey() so that we can report the correct 'master'
    // value here.
    return hook(makeRequestObject(original, model, false)).then((beforeSaveOverrideValue) => {
      debugPrint('HOOK', { beforeSaveOverrideValue });

      // Unlike BeforeDeleteResponse, BeforeSaveResponse might specify
      let objectToProceedWith = model;
      if (hookType === 'beforeSave' && beforeSaveOverrideValue) {
        objectToProceedWith = beforeSaveOverrideValue.toJSON();
      }

      return Parse.Promise.as(objectToProceedWith);
    });
  }
  return Parse.Promise.as(data);
}
function runHook ( className , hookType , data ) { let hook = getHook ( className , hookType ) ; if ( hook ) { const hydrate = ( rawData ) => { const modelData = Object . assign ( { } , rawData , { className } ) ; const modelJSON = _ . mapValues ( modelData , // Convert dates into JSON loadable representations value => ( ( value instanceof Date ) ? value . toJSON ( ) : value ) ) ; return Parse . Object . fromJSON ( modelJSON ) ; } ; const model = hydrate ( data , className ) ; hook = hook . bind ( model ) ; const collection = getCollection ( className ) ; let original ; if ( collection [ model . id ] ) { original = hydrate ( collection [ model . id ] ) ; } // TODO Stub out Parse.Cloud.useMasterKey() so that we can report the correct 'master' // value here. return hook ( makeRequestObject ( original , model , false ) ) . then ( ( beforeSaveOverrideValue ) => { debugPrint ( 'HOOK' , { beforeSaveOverrideValue } ) ; // Unlike BeforeDeleteResponse, BeforeSaveResponse might specify let objectToProceedWith = model ; if ( hookType === 'beforeSave' && beforeSaveOverrideValue ) { objectToProceedWith = beforeSaveOverrideValue . toJSON ( ) ; } return Parse . Promise . as ( objectToProceedWith ) ; } ) ; } return Parse . Promise . as ( data ) ; }
Executes a registered hook with data provided.

Hydrates the data into an instance of the class named by `className` param and binds it to the
function to be run.

@param {string} className The name of the class to get the hook on.
@param {string} hookType One of 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete'
@param {Object} data The Data that is to be hydrated into an instance of className class.
Executes a registered hook with data provided .