Question

Our durandal application has many modular UI components (all created using AMD constructor based viewmodels) and I would like to begin adding pub/sub communications. I need to determine the best way to ensure that subscriptions are 'cleaned up' properly.

When/how should these subscriptions be cleaned up?

The deactivate event seems to be sufficient for a select few viewmodels, but what about the rest? I don't see a particular mechanism which would allow a viewmodel to reliably 'clean up' after itself.

Before I go implementing some sort of disposable pattern, is there some obvious approach I'm missing here?

Followup question: Is there anything to be done other than calling subscription.off() to properly clean up?

Était-ce utile?

La solution

Calling subscription.off() from deactivate when working with view models or from detached when working with widgets should be all that's required. The event system has a bunch of test cases https://github.com/BlueSpire/Durandal/blob/master/test/specs/events.spec.js#L240, which could be used as starter for your own testing.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top