Is there a prescribed way to allow an activated viewmodel to signal to its activator that it should be closed/deactivated?
So far I've thought about having a "shouldClose" observable on the child viewmodel that the parent viewmodel can subscribe to and trigger deactivation that way. But that seems too contrived.
I also thought about raising an Event from the child viewmodel and have the parent viewmodel listen for that event.
I even thought about using Durandal's Pub/Sub mechanism to notify the parent viewmodel that the child should close. But that seemed like overkill.
Before I went any further I wanted to check if there's already a way to accomplish what I want.
Here's some basic code to illustrate what I'm trying to do:
Workspace.js
var Workspace = function () {
this.child = activator.create();
var vm = new SomeModule();
this.child.activateItem(vm);
/* I need this method to be triggered by the child view model (don't I?) */
this.child.deactivate(true);
Workspace.html
<button data-bind="click: showChild">Show Child</button>
<div data-bind="if: child()">
<div data-bind="compose: child"></div>
SomeModule.js
var SomeModule = function () {
canDeactivate: function() {
/* pretend there's logic here */
return true;
},
/* how to notify the controlling activator to deactivate/close? */
SomeModule.html
<button data-bind="click: close">Close</button>
</div>
Any guidance is greatly appreciated.