play JS router is slow, use it only for complex routes

This commit is contained in:
Thibault Duplessis 2014-11-14 00:55:17 +01:00
parent 5df54748e0
commit 0181e28870
8 changed files with 26 additions and 25 deletions

View file

@ -4,16 +4,16 @@
@helper.javascriptRouter("puzzleRoutes")( @helper.javascriptRouter("puzzleRoutes")(
routes.javascript.Puzzle.attempt, routes.javascript.Puzzle.attempt,
routes.javascript.Puzzle.show, routes.javascript.Puzzle.show,
routes.javascript.Puzzle.history, /* routes.javascript.Puzzle.history, */
routes.javascript.Puzzle.difficulty, /* routes.javascript.Puzzle.difficulty, */
routes.javascript.Puzzle.home, /* routes.javascript.Puzzle.home, */
routes.javascript.Puzzle.newPuzzle, /* routes.javascript.Puzzle.newPuzzle, */
routes.javascript.Puzzle.load, routes.javascript.Puzzle.load,
routes.javascript.Puzzle.vote, routes.javascript.Puzzle.vote,
routes.javascript.Coordinate.home, /* routes.javascript.Coordinate.home, */
routes.javascript.Editor.load, routes.javascript.Editor.load,
routes.javascript.Round.watcher, routes.javascript.Round.watcher,
routes.javascript.Auth.signup /* routes.javascript.Auth.signup */
)(ctx.req) )(ctx.req)
@embedJs { @embedJs {
LichessPuzzle( LichessPuzzle(

View file

@ -1,14 +1,15 @@
@()(implicit ctx: Context) @()(implicit ctx: Context)
@helper.javascriptRouter("roundRoutes")( @helper.javascriptRouter("roundRoutes")(
routes.javascript.Lobby.home, /* routes.javascript.Lobby.home */,
routes.javascript.Auth.signup, /* routes.javascript.Auth.signup */,
routes.javascript.User.show, /* routes.javascript.User.show */,
routes.javascript.Tournament.show, /* routes.javascript.Tournament.show */,
routes.javascript.Round.watcher, routes.javascript.Round.watcher,
routes.javascript.Round.playerText, routes.javascript.Round.playerText,
routes.javascript.Round.watcherText, routes.javascript.Round.watcherText,
routes.javascript.Round.sideWatcher, routes.javascript.Round.sideWatcher,
routes.javascript.Round.continue, routes.javascript.Round.continue,
routes.javascript.Tv.index, /* routes.javascript.Tv.index */,
routes.javascript.Tv.side, routes.javascript.Tv.side
routes.javascript.Editor.game)(ctx.req) /* routes.javascript.Editor.game */
)(ctx.req)

View file

@ -221,7 +221,7 @@ function buttons(ctrl) {
}, m('span[data-icon=B]')), }, m('span[data-icon=B]')),
m('a.button.hint--bottom', { m('a.button.hint--bottom', {
'data-hint': ctrl.trans('boardEditor'), 'data-hint': ctrl.trans('boardEditor'),
href: ctrl.router.Editor.game(ctrl.data.game.id).url + '?fen=' + ctrl.vm.situation.fen href: ctrl.data.game.id + '/edit?fen=' + ctrl.vm.situation.fen
}, m('span[data-icon=m]')), }, m('span[data-icon=m]')),
m('a.button.hint--bottom', { m('a.button.hint--bottom', {
'data-hint': ctrl.trans('continueFromHere'), 'data-hint': ctrl.trans('continueFromHere'),

View file

@ -25,7 +25,7 @@ module.exports = function(ctrl, player, klass) {
el.classList.add('ulpt'); el.classList.add('ulpt');
}, },
class: 'user_link ' + (player.user.online ? 'online is-green' : 'offline') + (klass ? ' ' + klass : ''), class: 'user_link ' + (player.user.online ? 'online is-green' : 'offline') + (klass ? ' ' + klass : ''),
href: ctrl.router.User.show(player.user.username).url, href: '/@/' + player.user.username,
target: game.isPlayerPlaying(ctrl.data) ? '_blank' : null, target: game.isPlayerPlaying(ctrl.data) ? '_blank' : null,
'data-icon': 'r', 'data-icon': 'r',
}, [ }, [

View file

@ -36,17 +36,17 @@ function renderTrainingBox(ctrl) {
m('h1', ctrl.trans('training')), m('h1', ctrl.trans('training')),
m('div.tabs.buttonset', [ m('div.tabs.buttonset', [
m('a.button.active', { m('a.button.active', {
href: ctrl.router.Puzzle.home().url href: '/training'
}, 'Puzzle'), }, 'Puzzle'),
m('a.button', { m('a.button', {
href: ctrl.router.Coordinate.home().url href: '/training/coordinate'
}, 'Coordinate') }, 'Coordinate')
]), ]),
ctrl.data.user ? renderUserInfos(ctrl) : m('div.register', [ ctrl.data.user ? renderUserInfos(ctrl) : m('div.register', [
m('p', ctrl.trans('toTrackYourProgress')), m('p', ctrl.trans('toTrackYourProgress')),
m('p.signup', m('p.signup',
m('a.button', { m('a.button', {
href: ctrl.router.Auth.signup().url href: '/signup',
}, ctrl.trans('signUp')) }, ctrl.trans('signUp'))
), ),
m('p', ctrl.trans('trainingSignupExplanation')) m('p', ctrl.trans('trainingSignupExplanation'))
@ -268,7 +268,7 @@ function renderHistory(ctrl) {
var hash = ctrl.data.user.history.join(''); var hash = ctrl.data.user.history.join('');
if (hash == context.hash) return; if (hash == context.hash) return;
context.hash = hash; context.hash = hash;
$.get(ctrl.router.Puzzle.history().url, function(html) { $.get('/training/history', function(html) {
el.innerHTML = html; el.innerHTML = html;
}); });
} }

View file

@ -45,7 +45,7 @@ function retry(ctrl) {
function setDifficulty(ctrl, d) { function setDifficulty(ctrl, d) {
m.request({ m.request({
method: 'POST', method: 'POST',
url: ctrl.router.Puzzle.difficulty().url, url: '/training/difficulty',
data: { data: {
difficulty: d difficulty: d
}, },
@ -56,7 +56,7 @@ function setDifficulty(ctrl, d) {
function newPuzzle(ctrl) { function newPuzzle(ctrl) {
m.request({ m.request({
method: 'GET', method: 'GET',
url: ctrl.router.Puzzle.newPuzzle().url, url: '/training/new',
config: xhrConfig config: xhrConfig
}).then(ctrl.reload); }).then(ctrl.reload);
} }

View file

@ -62,7 +62,7 @@ function renderButtons(ctrl, curPly) {
class: 'button flip hint--bottom' + (root.vm.flip ? ' active' : ''), class: 'button flip hint--bottom' + (root.vm.flip ? ' active' : ''),
'data-hint': root.trans('flipBoard'), 'data-hint': root.trans('flipBoard'),
}; };
if (root.data.tv) flipAttrs.href = root.router.Tv.index().url + (root.data.tv.flip ? '' : '?flip=1'); if (root.data.tv) flipAttrs.href = '/tv' + (root.data.tv.flip ? '' : '?flip=1');
else if (root.data.player.spectator) flipAttrs.href = root.router.Round.watcher(root.data.game.id, root.data.opponent.color).url; else if (root.data.player.spectator) flipAttrs.href = root.router.Round.watcher(root.data.game.id, root.data.opponent.color).url;
else flipAttrs.onclick = root.flip; else flipAttrs.onclick = root.flip;
return m('div.buttons', [ return m('div.buttons', [

View file

@ -124,17 +124,17 @@ module.exports = {
newGame: function(ctrl) { newGame: function(ctrl) {
if (!ctrl.data.offeringRematch && !ctrl.data.tournament) return m('a.lichess_new_game.button.hint--bottom', { if (!ctrl.data.offeringRematch && !ctrl.data.tournament) return m('a.lichess_new_game.button.hint--bottom', {
'data-hint': ctrl.trans('playWithAnotherOpponent'), 'data-hint': ctrl.trans('playWithAnotherOpponent'),
href: ctrl.router.Lobby.home().url href: '/',
}, ctrl.trans('newOpponent')); }, ctrl.trans('newOpponent'));
}, },
backToTournament: function(ctrl) { backToTournament: function(ctrl) {
if (ctrl.data.tournament) return m('a[data-icon=G].button' + (ctrl.data.tournament.running ? '.strong.glowing' : ''), { if (ctrl.data.tournament) return m('a[data-icon=G].button' + (ctrl.data.tournament.running ? '.strong.glowing' : ''), {
href: ctrl.router.Tournament.show(ctrl.data.tournament.id).url href: '/tournament/' + ctrl.data.tournament.id
}, ctrl.trans('backToTournament')); }, ctrl.trans('backToTournament'));
}, },
viewTournament: function(ctrl) { viewTournament: function(ctrl) {
if (ctrl.data.tournament) return m('a.button', { if (ctrl.data.tournament) return m('a.button', {
href: ctrl.router.Tournament.show(ctrl.data.tournament.id).url href: '/tournament/' + ctrl.data.tournament.id
}, ctrl.trans('viewTournament')); }, ctrl.trans('viewTournament'));
}, },
moretime: function(ctrl) { moretime: function(ctrl) {