Skip to content

Instantly share code, notes, and snippets.

@giuseppeg
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuseppeg/9638666 to your computer and use it in GitHub Desktop.
Save giuseppeg/9638666 to your computer and use it in GitHub Desktop.
a FlightJS mixin to teardown a group of components
define(function (require) {
var registry = require('flight/lib/registry');
return withTeardownColletion;
function withTeardownCollection() {
this.before('teardown', function () {
if (typeof this.attr.collectionName == 'string') {
Object.keys(registry.allInstances).forEach(function (instanceKey) {
var component = registry.allInstances[instanceKey].instance;
if (
/* component !== this && ?*/
component.attr.collectionName &&
component.attr.collectionName == this.attr.collectionName
) {
component.teardown();
}
}, this);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment