On

User events are overridden by name and weight, sorted by weight (desc) and must be namespaced.

class Foo {

  @on('axon__task.completed',  {   
    environment: 'development',   
  })
  static check(...params, runtime) {
    const {
      weight, 
      source,   // "script" or "event" 
      metadata,
      event,   
      context   // the event document, when fired by a user event.
    } = runtime

    console.log('checking')
  }

}

script.fire(event, ...params)

Execute events registered with @on in the same script context as the current principal.

Arguments

  • event { String[] } The custom event name. eg. axon__task.completed.before

  • ...params { *[] } Options object to pass to script.arguments

@on(event, options)

Arguments

  • event { String } Event

  • options { Object } Options object

    • active { Boolean = true }

    • name { String }

    • label { String }

    • environment { String = "*" }

    • if { Expression }

    • weight { Number = 0 }

Examples

const { on } = require('decorators')

class Handler {

  @on('axon__task.completed', { name: 'axon__task_completed_event' })
  onCompleted( task, str ) {
    // str === "another param"
  }

}

const task = completeATask()
script.fire('axon__task.completed', task, "another param")

Last updated