0
votes

In Master Detail sample on Durandal website, project.activate function is invoked two times each time when I change project in dropdown list.

First activation is invoked in write method of Activator. Second activation is invoked in composition.bindAndShow.

If I'm right, an obvious fix would be replacing (in index.html) this

<!--ko compose: activeProject--><!--/ko-->

with this

<!--ko compose: { model: activeProject, activate: false }--><!--/ko-->

but Durandal documentation says in Using Composition > Additional Settings > Activate:

Note: If you are using an activator, it will control the activation call and you should not attempt to manipulate it via the compose binding.

So I shouldn't do that. What is a proper way to fix this?

1

1 Answers

0
votes

As a workaround what about setting a runInit flag in the ctor, which gets set to false during activate?

var ctor = function(name, description) {
    this.runInit = true;
    this.name = name;
    this.description = description;
};


ctor.prototype.activate = function() {
    if (this.runInit){
        this.runInit = false;
        system.log('Model Activating', this);
    }
};

Live version available at http://dfiddle.github.io/dFiddle-2.0/#master-detail/so19719038

In addition I'd raise that as an issue https://github.com/BlueSpire/Durandal/issues?state=open to check if the double activation is expected or not.