# On

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

```javascript
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 } &#x20;
  * `environment` { String = *"\*"* }
  * `if` { Expression }
  * `weight` { Number = *0* }   &#x20;

## Examples

```javascript
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")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/decorators/static/on.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
