Remove Main.callbacknodes

This commit is contained in:
Zixaphir 2014-03-14 16:02:19 -07:00
parent 5581b53414
commit ca9abdc4e7
10 changed files with 103 additions and 183 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.4.1 - 2014-03-13
* 4chan X - Version 1.4.1 - 2014-03-14
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE

View File

@ -24,7 +24,7 @@
// ==/UserScript==
/*
* 4chan X - Version 1.4.1 - 2014-03-13
* 4chan X - Version 1.4.1 - 2014-03-14
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -849,24 +849,27 @@
}
};
Callbacks.prototype.execute = function(node) {
var err, errors, name, _i, _len, _ref;
_ref = this.keys;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
try {
if (!this[name].disconnected) {
this[name].call(node);
Callbacks.prototype.execute = function(nodes) {
var cb, err, errors, i, j, name, node;
i = 0;
while (name = this.keys[i++]) {
j = 0;
cb = this[name];
while (node = nodes[j++]) {
try {
if (!cb.disconnected) {
cb.call(node);
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node ', this.type, ' No.', node.ID, ' (', node.board, ').'].join(''),
error: err
});
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node ', this.type, ' No.', node.ID, ' (', node.board, ').'].join(''),
error: err
});
}
}
if (errors) {
@ -3319,8 +3322,8 @@
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, threads);
Main.callbackNodes(Post, posts);
Thread.callbacks.execute(threads);
Post.callbacks.execute(posts);
Index.updateHideLabel();
return $.event('IndexRefresh');
},
@ -3358,7 +3361,7 @@
if (errors) {
Main.handleErrors(errors);
}
return Main.callbackNodes(Post, posts);
return Post.callbacks.execute(posts);
},
buildCatalogViews: function() {
var catalogThreads, i, nodes, thread, _i, _len, _ref;
@ -3370,7 +3373,7 @@
catalogThreads.push(new CatalogThread(Build.catalogThread(thread), thread));
}
}
Main.callbackNodes(CatalogThread, catalogThreads);
CatalogThread.callbacks.execute(catalogThreads);
nodes = [];
i = 0;
while (thread = Index.sortedThreads[i++]) {
@ -3989,7 +3992,7 @@
return;
}
clone = post.addClone(context);
Main.callbackNodes(Clone, [clone]);
Clone.callbacks.execute([clone]);
nodes = clone.nodes;
$.rmAll(nodes.root);
$.add(nodes.root, nodes.post);
@ -4046,7 +4049,7 @@
board = g.boards[boardID] || new Board(boardID);
thread = g.threads["" + boardID + "." + threadID] || new Thread(threadID, board);
post = new Post(Build.postFromObject(post, boardID), thread, board);
Main.callbackNodes(Post, [post]);
Post.callbacks.execute([post]);
return Get.insert(post, root, context);
},
archivedPost: function(req, boardID, postID, root, context) {
@ -4115,7 +4118,7 @@
if ((_ref1 = $('.page-num', post.nodes.info)) != null) {
_ref1.hidden = true;
}
Main.callbackNodes(Post, [post]);
Post.callbacks.execute([post]);
return Get.insert(post, root, context);
},
parseMarkup: function(text) {
@ -9878,7 +9881,7 @@
ThreadUpdater.audio.play();
}
ThreadUpdater.lastPost = posts[count - 1].ID;
Main.callbackNodes(Post, posts);
Post.callbacks.execute(posts);
scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && Header.getBottomOf(ThreadUpdater.root) > -75;
for (_j = 0, _len1 = posts.length; _j < _len1; _j++) {
post = posts[_j];
@ -11539,7 +11542,7 @@
posts.push(post);
postsRoot.push(root);
}
Main.callbackNodes(Post, posts);
Post.callbacks.execute(posts);
$.after(a, postsRoot);
postsCount = postsRoot.length;
return a.textContent = ExpandThread.text('-', postsRoot.length, filesCount);
@ -12817,8 +12820,8 @@
makePost(post);
$.add(threadRoot, post);
}
Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts);
Thread.callbacks.execute([thread]);
Post.callbacks.execute(posts);
if (Conf['Quote Threading'] && !Conf['Unread Count']) {
QuoteThreading.force();
}
@ -13699,10 +13702,9 @@
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, threads);
Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
});
Thread.callbacks.execute(threads);
Post.callbacks.execute(posts);
$.event('4chanXInitFinished');
}
return $.get('previousversion', null, function(_arg) {
var changelog, el, previousversion;
@ -13722,40 +13724,6 @@
return $.set('previousversion', g.VERSION);
});
},
callbackNodes: function(klass, nodes) {
var cb, i, node;
i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) {
cb.execute(node);
}
},
callbackNodesDB: function(klass, nodes, cb) {
var cbs, fn, i, softTask;
i = 0;
cbs = klass.callbacks;
fn = function() {
var node;
if (!(node = nodes[i])) {
return false;
}
cbs.execute(node);
return ++i % 25;
};
softTask = function() {
while (fn()) {
continue;
}
if (!nodes[i]) {
if (cb) {
cb();
}
return;
}
return setTimeout(softTask, 0);
};
return softTask();
},
addCallback: function(e) {
var Klass, obj;
obj = e.detail;

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.4.1 - 2014-03-13
* 4chan X - Version 1.4.1 - 2014-03-14
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -903,24 +903,27 @@
}
};
Callbacks.prototype.execute = function(node) {
var err, errors, name, _i, _len, _ref;
_ref = this.keys;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
try {
if (!this[name].disconnected) {
this[name].call(node);
Callbacks.prototype.execute = function(nodes) {
var cb, err, errors, i, j, name, node;
i = 0;
while (name = this.keys[i++]) {
j = 0;
cb = this[name];
while (node = nodes[j++]) {
try {
if (!cb.disconnected) {
cb.call(node);
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node ', this.type, ' No.', node.ID, ' (', node.board, ').'].join(''),
error: err
});
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node ', this.type, ' No.', node.ID, ' (', node.board, ').'].join(''),
error: err
});
}
}
if (errors) {
@ -3378,8 +3381,8 @@
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, threads);
Main.callbackNodes(Post, posts);
Thread.callbacks.execute(threads);
Post.callbacks.execute(posts);
Index.updateHideLabel();
return $.event('IndexRefresh');
},
@ -3417,7 +3420,7 @@
if (errors) {
Main.handleErrors(errors);
}
return Main.callbackNodes(Post, posts);
return Post.callbacks.execute(posts);
},
buildCatalogViews: function() {
var catalogThreads, i, nodes, thread, _i, _len, _ref;
@ -3429,7 +3432,7 @@
catalogThreads.push(new CatalogThread(Build.catalogThread(thread), thread));
}
}
Main.callbackNodes(CatalogThread, catalogThreads);
CatalogThread.callbacks.execute(catalogThreads);
nodes = [];
i = 0;
while (thread = Index.sortedThreads[i++]) {
@ -4048,7 +4051,7 @@
return;
}
clone = post.addClone(context);
Main.callbackNodes(Clone, [clone]);
Clone.callbacks.execute([clone]);
nodes = clone.nodes;
$.rmAll(nodes.root);
$.add(nodes.root, nodes.post);
@ -4105,7 +4108,7 @@
board = g.boards[boardID] || new Board(boardID);
thread = g.threads["" + boardID + "." + threadID] || new Thread(threadID, board);
post = new Post(Build.postFromObject(post, boardID), thread, board);
Main.callbackNodes(Post, [post]);
Post.callbacks.execute([post]);
return Get.insert(post, root, context);
},
archivedPost: function(req, boardID, postID, root, context) {
@ -4174,7 +4177,7 @@
if ((_ref1 = $('.page-num', post.nodes.info)) != null) {
_ref1.hidden = true;
}
Main.callbackNodes(Post, [post]);
Post.callbacks.execute([post]);
return Get.insert(post, root, context);
},
parseMarkup: function(text) {
@ -9893,7 +9896,7 @@
ThreadUpdater.audio.play();
}
ThreadUpdater.lastPost = posts[count - 1].ID;
Main.callbackNodes(Post, posts);
Post.callbacks.execute(posts);
scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && Header.getBottomOf(ThreadUpdater.root) > -75;
for (_j = 0, _len1 = posts.length; _j < _len1; _j++) {
post = posts[_j];
@ -11553,7 +11556,7 @@
posts.push(post);
postsRoot.push(root);
}
Main.callbackNodes(Post, posts);
Post.callbacks.execute(posts);
$.after(a, postsRoot);
postsCount = postsRoot.length;
return a.textContent = ExpandThread.text('-', postsRoot.length, filesCount);
@ -12831,8 +12834,8 @@
makePost(post);
$.add(threadRoot, post);
}
Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts);
Thread.callbacks.execute([thread]);
Post.callbacks.execute(posts);
if (Conf['Quote Threading'] && !Conf['Unread Count']) {
QuoteThreading.force();
}
@ -13696,10 +13699,9 @@
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, threads);
Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
});
Thread.callbacks.execute(threads);
Post.callbacks.execute(posts);
$.event('4chanXInitFinished');
}
return $.get('previousversion', null, function(_arg) {
var changelog, el, previousversion;
@ -13719,40 +13721,6 @@
return $.set('previousversion', g.VERSION);
});
},
callbackNodes: function(klass, nodes) {
var cb, i, node;
i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) {
cb.execute(node);
}
},
callbackNodesDB: function(klass, nodes, cb) {
var cbs, fn, i, softTask;
i = 0;
cbs = klass.callbacks;
fn = function() {
var node;
if (!(node = nodes[i])) {
return false;
}
cbs.execute(node);
return ++i % 25;
};
softTask = function() {
while (fn()) {
continue;
}
if (!nodes[i]) {
if (cb) {
cb();
}
return;
}
return setTimeout(softTask, 0);
};
return softTask();
},
addCallback: function(e) {
var Klass, obj;
obj = e.detail;

View File

@ -81,7 +81,7 @@ Get =
# Stop here if the container has been removed while loading.
return unless root.parentNode
clone = post.addClone context
Main.callbackNodes Clone, [clone]
Clone.callbacks.execute [clone]
# Get rid of the side arrows/stubs.
{nodes} = clone
@ -136,7 +136,7 @@ Get =
thread = g.threads["#{boardID}.#{threadID}"] or
new Thread threadID, board
post = new Post Build.postFromObject(post, boardID), thread, board
Main.callbackNodes Post, [post]
Post.callbacks.execute [post]
Get.insert post, root, context
archivedPost: (req, boardID, postID, root, context) ->
# In case of multiple callbacks for the same request,
@ -209,7 +209,7 @@ Get =
new Thread threadID, board
post = new Post Build.post(o, true), thread, board, {isArchived: true}
$('.page-num', post.nodes.info)?.hidden = true
Main.callbackNodes Post, [post]
Post.callbacks.execute [post]
Get.insert post, root, context
parseMarkup: (text) ->
{

View File

@ -622,8 +622,8 @@ Index =
error: err
Main.handleErrors errors if errors
Main.callbackNodes Thread, threads
Main.callbackNodes Post, posts
Thread.callbacks.execute threads
Post.callbacks.execute posts
Index.updateHideLabel()
$.event 'IndexRefresh'
@ -649,13 +649,13 @@ Index =
$.add thread.OP.nodes.root.parentNode, nodes
Main.handleErrors errors if errors
Main.callbackNodes Post, posts
Post.callbacks.execute posts
buildCatalogViews: ->
catalogThreads = []
for thread in Index.sortedThreads when !thread.catalogView
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
Main.callbackNodes CatalogThread, catalogThreads
CatalogThread.callbacks.execute catalogThreads
nodes = []
i = 0
while thread = Index.sortedThreads[i++]

View File

@ -230,9 +230,10 @@ Main =
error: err
Main.handleErrors errors if errors
Main.callbackNodes Thread, threads
Main.callbackNodesDB Post, posts, ->
$.event '4chanXInitFinished'
Thread.callbacks.execute threads
Post.callbacks.execute posts
$.event '4chanXInitFinished'
$.get 'previousversion', null, ({previousversion}) ->
return if previousversion is g.VERSION
@ -245,31 +246,6 @@ Main =
Settings.open()
$.set 'previousversion', g.VERSION
callbackNodes: (klass, nodes) ->
i = 0
cb = klass.callbacks
while node = nodes[i++]
cb.execute node
return
callbackNodesDB: (klass, nodes, cb) ->
i = 0
cbs = klass.callbacks
fn = ->
return false unless node = nodes[i]
cbs.execute node
++i % 25
softTask = ->
while fn()
continue
unless nodes[i]
cb() if cb
return
setTimeout softTask, 0
softTask()
addCallback: (e) ->
obj = e.detail
unless typeof obj.callback.name is 'string'

View File

@ -312,8 +312,8 @@ Navigate =
makePost post
$.add threadRoot, post
Main.callbackNodes Thread, [thread]
Main.callbackNodes Post, posts
Thread.callbacks.execute [thread]
Post.callbacks.execute posts
QuoteThreading.force() if Conf['Quote Threading'] and not Conf['Unread Count']

View File

@ -10,14 +10,22 @@ class Callbacks
connect: (name) -> delete @[name].disconnected if @[name].disconnected
disconnect: (name) -> @[name].disconnected = true if @[name]
execute: (node) ->
for name in @keys
try
@[name].call node unless @[name].disconnected
catch err
errors = [] unless errors
errors.push
message: ['"', name, '" crashed on node ', @type, ' No.', node.ID, ' (', node.board, ').'].join('')
error: err
execute: (nodes) ->
i = 0
# c.time 'Features'
while name = @keys[i++]
j = 0
cb = @[name]
# c.time name
while node = nodes[j++]
try
cb.call node unless cb.disconnected
catch err
errors = [] unless errors
errors.push
message: ['"', name, '" crashed on node ', @type, ' No.', node.ID, ' (', node.board, ').'].join('')
error: err
# c.timeEnd name
# c.timeEnd 'Features'
Main.handleErrors errors if errors

View File

@ -100,7 +100,7 @@ ExpandThread =
filesCount++ if 'file' of post
posts.push post
postsRoot.push root
Main.callbackNodes Post, posts
Post.callbacks.execute posts
$.after a, postsRoot
postsCount = postsRoot.length

View File

@ -332,7 +332,7 @@ ThreadUpdater =
ThreadUpdater.audio.play()
ThreadUpdater.lastPost = posts[count - 1].ID
Main.callbackNodes Post, posts
Post.callbacks.execute posts
scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and Header.getBottomOf(ThreadUpdater.root) > -75