Function

Module: @ember/object
import { on } from '@ember/object/evented';
eventNames
String
func
Function
returns
Function
the listener function, passed as last argument to on(...)

Define a property as a function that should be executed when a specified event or events are triggered.

1
2
3
4
5
6
7
8
9
10
11
12
13
import EmberObject from '@ember/object';
import { on } from '@ember/object/evented';
import { sendEvent } from '@ember/object/events';

let Job = EmberObject.extend({
  logCompleted: on('completed', function() {
    console.log('Job completed!');
  })
});

let job = Job.create();

sendEvent(job, 'completed'); // Logs 'Job completed!'