Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Created January 20, 2015 20:45
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 mikaelbr/b55432849bcc12b0511c to your computer and use it in GitHub Desktop.
Save mikaelbr/b55432849bcc12b0511c to your computer and use it in GitHub Desktop.
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