Created
January 20, 2015 20:45
-
-
Save mikaelbr/b55432849bcc12b0511c 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
var component = require('omniscient'); | |
var react = require('react'); | |
var immstruct = require('immstruct'); | |
var appStructure = immstruct({ | |
currentUser: { | |
username: void 0 | |
} | |
}); | |
var Authentication = { | |
// like a class instance, will be called by react-router | |
statics: { | |
willTransitionTo: function (transition) { | |
// You can access the global state here. That isn't really | |
// connected to a specific component | |
if (appStructure.cursor('currentUser').deref() === void 0) { | |
Login.attemptedTransition = transition; | |
transition.redirect('/login'); | |
} | |
} | |
} | |
}; | |
var SecureComponent = component(Authentication, function () { | |
return React.DOM.h1({}, 'This is super secret'); | |
}); | |
appStructure.on('swap', render); | |
render(); | |
// Just with react-router, instead of rendering directly | |
function render () { | |
React.render(Welcome(structure.cursor()), document.body); | |
} | |
/* something like: (incomplete syntax) | |
var routes = ( | |
<Route handler={App}> | |
<Route name="secure" handler={SecureComponent.jsx}/> | |
</Route> | |
); | |
Route.render(routes, ...) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment