Skip to content

Instantly share code, notes, and snippets.

@Jaben
Last active December 20, 2015 08:19
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 Jaben/6099724 to your computer and use it in GitHub Desktop.
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.
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;
}
@Jaben
Copy link
Author

Jaben commented Jul 28, 2013

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment