Navigate rush condition

This commit is contained in:
Zixaphir 2014-07-29 00:03:50 -07:00
parent 51d6907c68
commit d9aa9f7fb8
4 changed files with 50 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/* /*
* appchan x - Version 2.9.32 - 2014-07-28 * appchan x - Version 2.9.32 - 2014-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE

View File

@ -28,7 +28,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* appchan x - Version 2.9.32 - 2014-07-28 * appchan x - Version 2.9.32 - 2014-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -16615,14 +16615,12 @@
if (view === 'thread') { if (view === 'thread') {
g.THREADID = +window.location.pathname.split('/')[3]; g.THREADID = +window.location.pathname.split('/')[3];
} }
if (view === g.VIEW) {
return;
}
$.rmClass(doc, g.VIEW);
$.addClass(doc, view);
({ ({
index: function() { index: function() {
var _ref; var _ref;
if (g.VIEW === view) {
return;
}
delete g.THREADID; delete g.THREADID;
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
Index.cb.toggleCatalogMode(); Index.cb.toggleCatalogMode();
@ -16630,15 +16628,24 @@
return (_ref = QR.posts[0]) != null ? _ref.thread = 'new' : void 0; return (_ref = QR.posts[0]) != null ? _ref.thread = 'new' : void 0;
}, },
thread: function() { thread: function() {
var _ref; var _ref, _ref1;
if (((_ref = QR.posts[0]) != null ? _ref.thread : void 0) === g.THREADID) {
return;
}
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
$.rmClass(doc, 'catalog-mode'); $.rmClass(doc, 'catalog-mode');
} }
return (_ref = QR.posts[0]) != null ? _ref.thread = g.THREADID : void 0; return (_ref1 = QR.posts[0]) != null ? _ref1.thread = g.THREADID : void 0;
} }
})[view](); })[view]();
QR.status(); if (view !== g.VIEW) {
return g.VIEW = view; $.rmClass(doc, g.VIEW);
$.addClass(doc, view);
g.VIEW = view;
}
return $.asap((function() {
return g.threads.keys.length;
}), QR.status);
}, },
updateBoard: function(boardID) { updateBoard: function(boardID) {
var current, fullBoardList; var current, fullBoardList;

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* appchan x - Version 2.9.32 - 2014-07-28 * appchan x - Version 2.9.32 - 2014-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -16631,14 +16631,12 @@
if (view === 'thread') { if (view === 'thread') {
g.THREADID = +window.location.pathname.split('/')[3]; g.THREADID = +window.location.pathname.split('/')[3];
} }
if (view === g.VIEW) {
return;
}
$.rmClass(doc, g.VIEW);
$.addClass(doc, view);
({ ({
index: function() { index: function() {
var _ref; var _ref;
if (g.VIEW === view) {
return;
}
delete g.THREADID; delete g.THREADID;
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
Index.cb.toggleCatalogMode(); Index.cb.toggleCatalogMode();
@ -16646,15 +16644,24 @@
return (_ref = QR.posts[0]) != null ? _ref.thread = 'new' : void 0; return (_ref = QR.posts[0]) != null ? _ref.thread = 'new' : void 0;
}, },
thread: function() { thread: function() {
var _ref; var _ref, _ref1;
if (((_ref = QR.posts[0]) != null ? _ref.thread : void 0) === g.THREADID) {
return;
}
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
$.rmClass(doc, 'catalog-mode'); $.rmClass(doc, 'catalog-mode');
} }
return (_ref = QR.posts[0]) != null ? _ref.thread = g.THREADID : void 0; return (_ref1 = QR.posts[0]) != null ? _ref1.thread = g.THREADID : void 0;
} }
})[view](); })[view]();
QR.status(); if (view !== g.VIEW) {
return g.VIEW = view; $.rmClass(doc, g.VIEW);
$.addClass(doc, view);
g.VIEW = view;
}
return $.asap((function() {
return g.threads.keys.length;
}), QR.status);
}, },
updateBoard: function(boardID) { updateBoard: function(boardID) {
var current, fullBoardList; var current, fullBoardList;

View File

@ -103,28 +103,36 @@ Navigate =
return return
updateContext: (view) -> updateContext: (view) ->
# State tracking
g.DEAD = false g.DEAD = false
g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread' g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread'
return if view is g.VIEW
$.rmClass doc, g.VIEW
$.addClass doc, view
{ {
index: -> index: ->
# Unlike threads, boards don't need to do much when switching between them that the QR doesn't already handle.
return if g.VIEW is view
delete g.THREADID delete g.THREADID
Index.cb.toggleCatalogMode() if Conf['Index Mode'] is 'catalog' Index.cb.toggleCatalogMode() if Conf['Index Mode'] is 'catalog'
QR.posts[0]?.thread = 'new' QR.posts[0]?.thread = 'new'
thread: -> thread: ->
return if QR.posts[0]?.thread is g.THREADID
$.rmClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog' $.rmClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog'
# When switching between threads, we need to update the QR state to avoid posting in the wrong thread.
# Maybe address this in a loop to update all posts to the current thread?
QR.posts[0]?.thread = g.THREADID QR.posts[0]?.thread = g.THREADID
}[view]() }[view]()
QR.status() # Re-enable the QR in the case of a 404'd thread or something. if view isnt g.VIEW # index and thread are really all we care about here.
# Update some CSS selectors that depend on thread and index views.
$.rmClass doc, g.VIEW
$.addClass doc, view
# Tell the rest of the script we're no longer in the view we were.
g.VIEW = view
g.VIEW = view # Re-enable the QR in the case of a 404'd thread or something.
# Race Condition: g.threads may not have been fully rebuilt by the time we attempt to access it.
$.asap (-> g.threads.keys.length), QR.status
updateBoard: (boardID) -> updateBoard: (boardID) ->
fullBoardList = $ '#full-board-list', Header.boardList fullBoardList = $ '#full-board-list', Header.boardList