src/models/make-ports.js
/**
 * Register an event handler that invokes this `port`.
 * @param {string} portName
 * @param {import('.').ports[portName]} portConf
 * @param {import("./observer").Observer} observer
 * @param {boolean} disabled
 * @returns {boolean} whether or not to remember this port
 * for compensation and restart
 */
Register an event handler that invokes this `port`.
Register an event handler that invokes this ` port ` .
function addPortListener(portName, portConf, observer, disabled) {
  if (disabled) return false;
  if (portConf.consumesEvent) {
    const callback = getPortCallback(portConf.callback);
    observer.on(
      portConf.consumesEvent,
      async function ({ eventName, model }) {
        if (await isUndoRunning(model)) {
          console.warn("undo running, canceling port operation");
          return;
        }
        if (model.getPortFlow().includes(portName)) {
          console.info("port already invoked");
          return;
        }
        console.info(`event ${eventName} fired: calling port ${portName}`);
        await async(model[portName](callback));
      },
      false
    );
    return true;
  }
  return false;
}
function addPortListener ( portName , portConf , observer , disabled ) { if ( disabled ) return false ; if ( portConf . consumesEvent ) { const callback = getPortCallback ( portConf . callback ) ; observer . on ( portConf . consumesEvent , async function ( { eventName , model } ) { if ( await isUndoRunning ( model ) ) { console . warn ( "undo running, canceling port operation" ) ; return ; } if ( model . getPortFlow ( ) . includes ( portName ) ) { console . info ( "port already invoked" ) ; return ; } console . info ( ` ${ eventName } ${ portName } ` ) ; await async ( model [ portName ] ( callback ) ) ; } , false ) ; return true ; } return false ; }
Register an event handler that invokes this `port`.
Register an event handler that invokes this ` port ` .
// listen for triggering event // Don't call any more ports if we are reversing a transaction. // invoke this port