packages/mangojuice-core/src/classes/Process.js
function bindChild(proc, model, key, childCmd) {
  const { logicClass, updateMsg, createArgs } = childCmd;
  const originalModel = model[key];
  let actualModel = originalModel || {};
  let currProc = procOf(actualModel);

  // Protect update of the model of the same type
  if (updateMsg && (!currProc || !(currProc.logic instanceof logicClass))) {
    proc.logger.onCatchError(new Error('Child model does not exists or have incorrect type'), proc);
    return;
  }

  // Re-run prepare with new config args if proc already running
  // with the same logic class, otherwise destroy the logic
  if (currProc) {
    if (!updateMsg) {
      currProc.destroy();
      currProc = null;
      actualModel = {};
    } else {
      runLogicUpdate(currProc, updateMsg);
    }
  }

  // Run new process for given child definition if no proc was
  // binded to the model or if it was destroyed
  if (!currProc) {
    const shouldRehydrate = actualModel && actualModel === originalModel;
    currProc = new proc.constructor({
      createArgs,
      logicClass,
      parent: proc,
      logger: proc.logger,
      contexts: proc.contexts,
      internalContext: proc.internalContext
    });
    model[key] = actualModel;
    currProc.bind(actualModel);
    currProc.run(shouldRehydrate);
    proc.children[currProc.id] = currProc;
  }

  return currProc;
}
function bindChild(proc, model, key, childCmd) {
  const { logicClass, updateMsg, createArgs } = childCmd;
  const originalModel = model[key];
  let actualModel = originalModel || {};
  let currProc = procOf(actualModel);

  // Protect update of the model of the same type
  if (updateMsg && (!currProc || !(currProc.logic instanceof logicClass))) {
    proc.logger.onCatchError(new Error('Child model does not exists or have incorrect type'), proc);
    return;
  }

  // Re-run prepare with new config args if proc already running
  // with the same logic class, otherwise destroy the logic
  if (currProc) {
    if (!updateMsg) {
      currProc.destroy();
      currProc = null;
      actualModel = {};
    } else {
      runLogicUpdate(currProc, updateMsg);
    }
  }

  // Run new process for given child definition if no proc was
  // binded to the model or if it was destroyed
  if (!currProc) {
    const shouldRehydrate = actualModel && actualModel === originalModel;
    currProc = new proc.constructor({
      createArgs,
      logicClass,
      parent: proc,
      logger: proc.logger,
      contexts: proc.contexts,
      internalContext: proc.internalContext
    });
    model[key] = actualModel;
    currProc.bind(actualModel);
    currProc.run(shouldRehydrate);
    proc.children[currProc.id] = currProc;
  }

  return currProc;
}
function bindChild ( proc , model , key , childCmd ) { const { logicClass , updateMsg , createArgs } = childCmd ; const originalModel = model [ key ] ; let actualModel = originalModel || { } ; let currProc = procOf ( actualModel ) ; // Protect update of the model of the same type if ( updateMsg && ( ! currProc || ! ( currProc . logic instanceof logicClass ) ) ) { proc . logger . onCatchError ( new Error ( 'Child model does not exists or have incorrect type' ) , proc ) ; return ; } // Re-run prepare with new config args if proc already running // with the same logic class, otherwise destroy the logic if ( currProc ) { if ( ! updateMsg ) { currProc . destroy ( ) ; currProc = null ; actualModel = { } ; } else { runLogicUpdate ( currProc , updateMsg ) ; } } // Run new process for given child definition if no proc was // binded to the model or if it was destroyed if ( ! currProc ) { const shouldRehydrate = actualModel && actualModel === originalModel ; currProc = new proc . constructor ( { createArgs , logicClass , parent : proc , logger : proc . logger , contexts : proc . contexts , internalContext : proc . internalContext } ) ; model [ key ] = actualModel ; currProc . bind ( actualModel ) ; currProc . run ( shouldRehydrate ) ; proc . children [ currProc . id ] = currProc ; } return currProc ; }
Create process and bind the process to child model
with given name. If model field is empty then do nothing.
If model already binded to some model do nothing.
Return true if model sucessfully binded to the process.
Othersise returns false

@private
@param  {Object} childModel
@param  {String} fieldName
@return {Boolean}
Create process and bind the process to child model with given name . If model field is empty then do nothing . If model already binded to some model do nothing . Return true if model sucessfully binded to the process . Othersise returns false