Using activators
The activation life cycle is automatically used by the router, but sometimes, you want to use it without tying the work to the URL, which turns out to be quite easy. An activator is just a computed observable whose write function enforces the life cycle. An activator can be created by calling activator.create()
using the durandal/activator
module.
For this example, we are going to add an inline quick edit to the list page that will allow contacts to be edited without navigating to another page. It will leverage the existing edit page viewmodel with some minor changes, as it already has a canDeactivate
method that prompts the user with a confirmation modal when unsaved changes are present. The list page activator will hook into the same logic automatically.
This example is in the cp6-activator
branch. You might want to play with it a bit before we go into how it works. Just use the quick edit button on the list page, and the contact will be loaded into an edit form just below...