Using Activators

####

Key Points

Creating an Activator

To create an activator, require the activator module and call the create method. An activator is just a computed observable with special behavior. The details of its API can be found here.

Here's an example UI that models a screen with activatable content:

var screen = {
    content:activator.create(),
    sidebar:ko.observable(),
    openDocument:function(docModel){
        this.content.activateItem(docModel)
    },
    showEditor:function(editorModel){
        this.sidebar(editorModel);
    }
};

In this example, any time the content is changed, through calls to activateItem, the activation lifecycle will kick in on the old/new values.

Lifecycle

The activator enforces a lifecycle on all its values. Other than that, it operates like a standard computed observable. Below is an explanation of the lifecycle events you can hook into for advanced screen scenarios. To participate in the lifecycle, implement any (or none) of the functions below on the object that you set the activator to: