Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created March 11, 2015 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liammclennan/50d58f366b99f38f5926 to your computer and use it in GitHub Desktop.
Save liammclennan/50d58f366b99f38f5926 to your computer and use it in GitHub Desktop.
Euclid usage
euclid.start([{
title: 'Home',
entry: function () {
return server.getDecks().then(function (decks) {
loginChanges();
var data = {decks: decks};
return [components.Home(data), data];
}, function () {
return [components.NotAuthenticated(), {}];
});
},
actions: {
importDemo: function () {
var props = this,
url = 'https://github.com/liammclennan/maths.wiki.git';
return server.importGitWiki(url).then(function () {
euclid.navigate('Deck', {url: encodeURIComponent(btoa(url))});
return props;
});
}
}
},
{
title: 'Login',
entry: function () {
logoutChanges();
var data = {};
return [components.LoginPage(data), data];
},
actions: {
login: function (email) {
var props = this;
return server.login(email).then(function () {
props.message = "An login email has been sent to your email address " + email + '. Check your email and follow the login link.';
return props;
});
}
}
}]);
@liammclennan
Copy link
Author

  • An array of page objects is passed to euclid.start.
  • Each page object defines a page.
  • title doubles as the page route.
  • Any route parameters are passed to the entry function.
  • The entry function is expected to return an array containing [, ] or a promise containing the same.
  • Actions define the things that the page can do. When the user does something on that page (submit a form or whatever) the react component delegates to one of the actions. Each action mutates the page data (props) and returns the updated state.

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