webgme / webgme-engine

WebGME server and Client API without a GUI
MIT License
11 stars 7 forks source link

Dispatch events about invocations to the client-core api #297

Open pmeijer opened 1 year ago

pmeijer commented 1 year ago

This differs from regular client-territories in that it:

Note that the event-handler will only be invoked after the commit has been persisted in the database. (The event-data contains the commitStatus to check the status of the commit.)

Example of how to use:

function eventHandler(client_, data) {
  // meta-data
  console.log(data.projectId); // e.g. 'guest+MyProject'
  console.log(data.branchName); // e.g. 'master'
  console.log(data.prevRootHash); // root-hash where the changes were applied
  console.log(data.prevCommitHash); // commit-hash where the changes were applied
  console.log(JSON.stringify(data.commitObject)); // contains time-stamp, userId, and hashes for new state
  console.log(data.commitStatus); // e.g. 'SYNCED', see client.CONSTANTS.STORAGE
  // callSequence is an array of objects - each one describing an invocation within a currently open transaction
  const call1 = data.callSequence[0];
  console.log(call1.name); // e.g. 'setAttribute'
  console.log(call1.args); // e.g. ['/node/path', 'name', 'ANewName', 'commit Message']
  console.log(call1.return); // e.g. undefined
}

client.addEventListener(client.CONSTANTS.CORE_CALL_SEQUENCE, eventHandler);

Cleaning up handlers...

client.removeEventListener(client.CONSTANTS.CORE_CALL_SEQUENCE, eventHandler);