Created
January 4, 2016 21:52
-
-
Save hwclass/cac01eb8a87636b3c317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stop: function() { | |
var behaviorInstance, moduleBehaviors; | |
if (!Array.isArray(arguments)) { | |
var element = arguments; | |
var instanceData = getInstanceDataByElement(element); | |
if (!instanceData) { | |
if (globalConfig.debug) { | |
error(new Error('Unable to stop module associated with element: ' + element.id)); | |
return this; | |
} | |
} else { | |
unbindEventListeners(instanceData); | |
// Call these in reverse order | |
moduleBehaviors = getBehaviors(instanceData); | |
for (var i = moduleBehaviors.length - 1; i >= 0; i--) { | |
behaviorInstance = moduleBehaviors[i]; | |
callModuleMethod(behaviorInstance, 'destroy'); | |
} | |
callModuleMethod(instanceData.instance, 'destroy'); | |
delete instances[element.id]; | |
} | |
} else if (Array.isArray(arguments)) { | |
var instanceArrayOfData = []; | |
for (var elementsIndex = 0, len = arguments.length; elementsIndex < len; elementsIndex++) { | |
instanceArrayOfData.push(getInstanceDataByElement(arguments[elementsIndex])); | |
if (!instanceArrayOfData[elementsIndex]) { | |
if (globalConfig.debug) { | |
error(new Error('Unable to stop module associated with element: ' + arguments[elementsIndex].id)); | |
return this; | |
} | |
} else { | |
unbindEventListeners(instanceArrayOfData[elementsIndex]); | |
moduleBehaviors = getBehaviors(instanceArrayOfData[elementsIndex]); | |
for (var behaviorsIndex = moduleBehaviors.length - 1; behaviorsIndex >= 0; behaviorsIndex--) { | |
behaviorInstance = moduleBehaviors[behaviorsIndex]; | |
callModuleMethod(behaviorInstance, 'destroy'); | |
} | |
callModuleMethod(instanceArrayOfData[elementsIndex].instance, 'destroy'); | |
delete arguments[elementsIndex].id; | |
} | |
} | |
} | |
return this; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment