Public Method Author API

once()

Set up a one-time event listener for a specified event that will execute the callback function once and then stop listening to the event.

You would want to use this method so that you can execute some custom logic the first time an event is fired, such as displaying a message the first time the author creates an Item, for example.

Examples

// Execute only once, the first time any Item has been saved.
authorApp.once('save:success', function (event) {
    console.log('Item has been saved.');
});

// Multiple events can be listened to (just once) using chained calls.
authorApp
    .once('widgetedit:widget:changed', function (event) {
        console.log('The Widget has changed.');
    })
    .once('widgetedit:preview:changed', function (event) {
        console.log('The preview has changed.');
    });

Arguments

  • eventName string

    Name of the event that you want to listen to.

  • eventCallback eventCallback

    Callback function that will be invoked whenever the event is fired.

  • context object

    Execution context that will be used for this when the callback function is invoked.

Return value

AuthorApp

Returns the current instance of Author API if successful.

Related articles

  • Author API events
  • The on() method, which allows you to unbind event listeners.
  • The off() method, which allows you to unbind event listeners.
Was this article helpful?