Skip to content

Instantly share code, notes, and snippets.

@maxidr
Last active August 29, 2015 14:26
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 maxidr/92816444bd577a758e0b to your computer and use it in GitHub Desktop.
Save maxidr/92816444bd577a758e0b to your computer and use it in GitHub Desktop.
#mithril Route separation logic example From https://gitter.im/lhorie/mithril.js?at=551bd24305184cd235fb971a
// The limited unauthenticated routemap
var authRoutes = {
'/signup' : modules.signup,
'/login' : modules.login
};
// The whole shebang
var appRoutes = Object.assign( {
'/:semantic/:app/:routes' : various.modules
}, authRoutes );
// Called on succesful login
function welcome(){
m.startComputation();
m.route( document.body, '/profile', appRoutes );
// Where they were going to in the first place
m.route( localStorage.getItem( 'entryPoint' ) );
m.endComputation();
}
// Run on init
m.route( document.body, '/', {
'/:path...' : {
controller(){
// Preserve entry point
localStorage.setItem( 'entryPoint', m.route() );
},
// Wait til we've determined what's going on
view : mod.call( undefined, modules.loading )
}
} );
// Record of a local session
if( var profile = localStorage.getItem( 'profile' ) ){
// Check to see if it's still ongoing server-side
m.request( profile.profile_uri ).then(
// Fork journey depending on outcome
() => m.route( document.body, '/', appRoutes ),
() => m.route( document.body, '/login', authRoutes )
);
}
else {
// Vanilla routing
m.route( document.body, '/signup', authRoutes );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment