Created
November 4, 2015 21:40
-
-
Save peisenmann/ac402e0fdae1260b706a to your computer and use it in GitHub Desktop.
Aurelia preconditions for load
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
import * as DataServices from './data/services/index'; | |
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging(); | |
prestart(aurelia).then( | |
() => start(aurelia), | |
err => preconditionsFailed(err, aurelia) | |
); | |
} | |
function prestart(aurelia) { | |
let dataPromises = []; | |
for (let serviceName in DataServices) { | |
let serviceInstance = aurelia.container.get(DataServices[serviceName]); | |
dataPromises.push(serviceInstance.loadInitialState()); | |
} | |
return Promise.all(dataPromises); | |
} | |
function start(aurelia) { | |
return aurelia.start().then(a => a.setRoot()); | |
} | |
function preconditionsFailed(err, aurelia) { | |
return Promise.resolve().then(() => { | |
console.log("Failed to start due to failure during preconditions.", err); | |
alert("Failed to start due to failure during preconditions."); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment