Last active
December 20, 2015 08:19
-
-
Save Jaben/6099724 to your computer and use it in GitHub Desktop.
Patch to 'Fix' Durandal v1.x Loading in Router.js for TypeScript AMD requireJS.
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
getActivatableInstance: function (routeInfo, params, module) { | |
var afterDash = function (str) { | |
var dashIndex = str.lastIndexOf("/", str.length - 1); | |
return str.substr(dashIndex+1, str.length - dashIndex); | |
}; | |
var findPropCaseInsensitive = function(obj, propName) { | |
propLower = propName.toLowerCase(); | |
for (var prop in obj) { | |
if (prop.toLowerCase() === propLower) { | |
return prop; | |
} | |
} | |
return null; | |
} | |
var instance = module; | |
if (typeof module == 'function') { | |
instance = new module(); | |
} else { | |
var possibleExports = [afterDash(routeInfo.moduleId), afterDash(routeInfo.moduleId) + "View"]; | |
for (var i = 0; i < possibleExports.length; i++) { | |
var prop = findPropCaseInsensitive(module, possibleExports[i]); | |
if (typeof module[prop] === "object") { | |
instance = module[prop]; | |
break; | |
} | |
else if (typeof module[prop] === 'function') { | |
instance = new module[prop](); | |
break; | |
} | |
} | |
} | |
instance.moduleId = routeInfo.moduleId; | |
return instance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the getActivatableInstance function in router.js. WIll use the export in the viewmodel of moduleId or moduleIdView. E.g. for 'viewmodel/testing' it will look for export "testing" and "testingView".