Events
Configs
4
Configs
4Common
The listener set for this object.
An object whose property names are the names of events to handle, or options which modifiy how the handlers are called.
See addListener for details about the options.
Listeners can be specified in target class config and they will be merged with any listeners specified in the instantiation config. Class listeners will be fired first:
class MyStore extends Store({
static configurable = {
listeners : {
myCustomEvent() {
},
load : {
prio : 10000,
fn() { // this load listener handles things first }
}
}
};
});
let store = new MyStore({
listeners: {
load: () => { // This load listener runs after the class's },
...
}
});
Handlers as function name
Object event handlers may be specified as a function name. If a string is specified, it is the name
of the function in the thisObj object.
If the string begins with up., this object's ownership hierarchy
(if present) is scanned for an object which implements that function name:
new Popup({
tbar : {
items : {
myCombo : {
type : 'combo',
editable : false,
label : 'Type',
listeners : {
// Look in owner chain for this function name
change : 'up.onFilterChange'
},
items : [
'Event',
'Task',
'Appointment'
]
}
}
},
items : {
...
},
onFilterChange({ value }) {
// Handle event type selection here
}
});
Misc
An object where property names with a truthy value indicate which events should bubble up the ownership hierarchy when triggered.
const container = new Container({
items : [
{ type : 'text', bubbleEvents : { change : true }}
],
listeners : {
change() {
// Will catch change event from the text field
}
}
});
Set to true to call onXXX method names (e.g. onShow, onClick), as an easy way to listen for events.
const container = new Container({
callOnFunctions : true
onHide() {
// Do something when the 'hide' event is fired
}
});
Other
By default, if an event handler throws an exception, the error propagates up the stack and the application state is undefined. Code which follows the event handler will not be executed.
Set this to true to catch exceptions thrown by this object's event handlers and continue processing the event.
The exception will be rethrown on a zero millisecond timeout, so it will not destroy the stack.
Properties
4
Properties
4Class hierarchy
Misc
Set to true to call onXXX method names (e.g. onShow, onClick), as an easy way to listen for events.
const container = new Container({
callOnFunctions : true
onHide() {
// Do something when the 'hide' event is fired
}
});
Other
By default, if an event handler throws an exception, the error propagates up the stack and the application state is undefined. Code which follows the event handler will not be executed.
Set this to true to catch exceptions thrown by this object's event handlers and continue processing the event.
The exception will be rethrown on a zero millisecond timeout, so it will not destroy the stack.
Functions
10
Functions
10Adds an event listener. This method accepts parameters in the following format:
myObject.addListener({
thisObj : this, // The this reference for the handlers
eventname2 : 'functionName' // Resolved at invocation time using the thisObj,
otherevent : {
fn : 'handlerFnName',
once : true // Just this handler is auto-removed on fire
},
yetanother : {
fn : 'yetAnotherHandler',
args : [ currentState1, currentState2 ] // Capture info to be passed to handler
},
prio : 100 // Higher prio listeners are called before lower
});
When listeners have a thisObj option, they are linked to the lifecycle of that object.
When it is destroyed, those listeners are removed.
The config parameter allows supplying options for the listener(s), for available options see BryntumListenerConfig.
A simpler signature may be used when only adding a listener for one event and no extra options
(such as once or delay) are required:
myObject.addListener('click', myController.handleClicks, myController);
The args in this simple case are eventName, handler and thisObj
By default, if an event handler throws an exception, the error propagates up the stack and the
application state is undefined. Code which follows the event handler will not be executed. Set the
catchEventHandlerExceptions config to true to catch exceptions thrown by this object's event handlers
and allow the event to continue processing. The exception will be rethrown on a zero millisecond timeout,
| Parameter | Type | Description |
|---|---|---|
config | BryntumListenerConfig | String | An object containing listener definitions, or the event name to listen for |
thisObj | Object | function | Default |
oldThisObj | Object | The |
Returns a detacher function unless configured with detachable: false. Call detacher to remove listeners
Returns true if any listener is registered for the specified eventName, or if null, for any event.
| Parameter | Type | Description |
|---|---|---|
eventName | String | The event to test for listeners, or |
true if listener is registered, otherwise false
Alias for addListener. Adds an event listener. This method accepts parameters in the following format:
myObject.on({
thisObj : this, // The this reference for the handlers
eventname2 : 'functionName' // Resolved at invocation time using the thisObj,
otherevent : {
fn : 'handlerFnName',
once : true // Just this handler is auto-removed on fire
},
yetanother : {
fn : 'yetAnotherHandler',
args : [ currentState1, currentState2 ] // Capture info to be passed to handler
},
prio : 100 // Higher prio listeners are called before lower
});
When listeners have a thisObj option, they are linked to the lifecycle of that object.
When it is destroyed, those listeners are removed.
The config parameter allows supplying options for the listener(s), for available options see BryntumListenerConfig.
A simpler signature may be used when only adding a listener for one event and no extra options
(such as once or delay) are required:
myObject.on('click', myController.handleClicks, myController);
The args in this simple case are eventName, handler and thisObj
| Parameter | Type | Description |
|---|---|---|
config | BryntumListenerConfig | String | An object containing listener definitions, or the event name to listen for |
thisObj | Object | function | Default |
oldThisObj | Object | The |
Returns a detacher function unless configured with detachable: false. Call detacher to remove listeners
Relays all events through another object that also implements Events mixin. Adds a prefix to the event name before relaying, for example add -> storeAdd
// Relay all events from store through grid, will make it possible to listen for store events prefixed on grid:
'storeLoad', 'storeChange', 'storeRemoveAll' etc.
store.relayAll(grid, 'store');
grid.on('storeLoad', () => console.log('Store loaded');
| Parameter | Type | Description |
|---|---|---|
through | Events | Object to relay the events through, needs to mix Events mixin in |
prefix | String | Prefix to add to event name |
transformCase | Boolean | Specify false to prevent making first letter of event name uppercase |
Removes all listeners registered to this object by the application.
Removes an event listener. Same API signature as addListener
| Parameter | Type | Description |
|---|---|---|
config | Object | String | A config object or the event name |
thisObj | Object | function |
|
oldThisObj | Object |
|
true if at least one listener was found and removed
Resume event triggering after a call to suspendEvents(). If any triggered events were queued they will be triggered.
true if events have been resumed (multiple calls to suspend require an equal number of resume calls to resume).
Prevents events from being triggered until resumeEvents() is called. Optionally queues events that are triggered while
suspended. Multiple calls stack to require matching calls to resumeEvents() before actually resuming.
| Parameter | Type | Description |
|---|---|---|
queue | Boolean | Specify true to queue events triggered while suspended |
Triggers an event, calling all registered listeners with the supplied arguments. Returning false from any listener makes function return false.
By default, if an event handler throws an exception, the error propagates up the stack and the
application state is undefined. Code which follows the event handler will not be executed. Set the
catchEventHandlerExceptions config to true to catch exceptions thrown by this object's event handlers
and allow the event to continue processing. The exception will be rethrown on a zero millisecond timeout,
| Parameter | Type | Description |
|---|---|---|
eventName | String | Event name for which to trigger listeners |
param | Object | Single parameter passed on to listeners, source property will be added to it (this) |
param.bubbles | Boolean | Pass as |
Returns false if any listener returned false, or a Promise yielding
true / false based on what is returned from the async listener functions, otherwise true
Shorthand for removeListener
| Parameter | Type | Description |
|---|---|---|
config | Object | String | A config object or the event name |
thisObj | Object | function |
|
oldThisObj | Object |
|
true if at least one listener was found and removed
Events
3
Events
3Fires before an object is destroyed.
// Adding a listener using the "on" method
events.on('beforeDestroy', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Base | The Object that is being destroyed. |
Fires when any other event is fired from the object.
Note: catchAll is fired for both public and private events. Please rely on the public events only.
// Adding a listener using the "on" method
events.on('catchAll', ({ event, event.type }) => {
});| Parameter | Type | Description |
|---|---|---|
event | Object | The Object that contains event details |
event.type | String | The type of the event which is caught by the listener |
Event handlers
3
Event handlers
3Called before an object is destroyed.
new Events({
onBeforeDestroy({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Base | The Object that is being destroyed. |
Called when any other event is called from the object.
Note: catchAll is called for both public and private events. Please rely on the public events only.
new Events({
onCatchAll({ event }) {
}
});| Parameter | Type | Description |
|---|---|---|
event | Object | The Object that contains event details |
event.type | String | The type of the event which is caught by the listener |
Typedefs
1
Typedefs
1| Parameter | Type | Description |
|---|---|---|
thisObj | Object | The |
once | Boolean | Specify as |
expires | Number | Object | The listener only waits for a specified time before being removed. The value may be a number or an object containing an expiry handler. |
expires.delay | Number | How long to wait for the event for. |
expires.alt | String | function | The function to call when the listener expires without having been triggered. |
args | Object[] | An array of arguments to be passed to the handler before the event object. |
prio | Number | The priority for all listeners; higher priority listeners are called before lower. |
buffer | Number | A buffer time in milliseconds to wait after last event trigger to call the handler, to reduce the amount of handler calls for frequent events. |
throttle | Number | A millisecond timeout value to throttle event triggering. With it specified a handler will be called once immediately and then all following calls during the timeout period will be grouped together into one call once per throttle period. |
asap | Boolean | Specify as |