I get asked a lot, "do you even test your code?"

No. No, the answer is no.
This commit is contained in:
Zixaphir 2014-01-07 14:18:22 -07:00
parent f067d990c6
commit 31e409f361
4 changed files with 49 additions and 85 deletions

View File

@ -813,7 +813,7 @@
Callbacks.prototype.push = function(_arg) { Callbacks.prototype.push = function(_arg) {
var cb, name; var cb, name;
name = _arg.name, cb = _arg.cb; name = _arg.name, cb = _arg.cb;
return this.name = cb; return this[name] = cb;
}; };
Callbacks.prototype.clean = function() { Callbacks.prototype.clean = function() {
@ -826,16 +826,15 @@
}; };
Callbacks.prototype.rm = function(name) { Callbacks.prototype.rm = function(name) {
return delete this.name; return delete this[name];
}; };
Callbacks.prototype.execute = function(target) { Callbacks.prototype.execute = function(node) {
var cb, err, errors, name; var err, errors, name;
for (name in this) { for (name in this) {
cb = this[name];
if (this.hasOwnProperty(name)) { if (this.hasOwnProperty(name)) {
try { try {
cb.call(target); this[name].call(node);
} catch (_error) { } catch (_error) {
err = _error; err = _error;
if (!errors) { if (!errors) {
@ -12571,43 +12570,32 @@
} }
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var len, node; var cb, i, node;
len = nodes.length; i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) { while (node = nodes[i++]) {
klass.callback.execute(node); cb.execute(node);
} }
}, },
callbackNodesDB: function(klass, nodes, cb) { callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask; var callbacks, errors, len, softTask;
queue = [];
errors = null; errors = null;
func = function(node) { len = 0;
klass.callback.execute(node); callbacks = klass.callbacks;
if (!queue.length) {
if (cb) {
return cb();
}
}
};
softTask = function() { softTask = function() {
var node; var node;
node = queue.shift(); node = nodes.shift();
func(node); callbacks.execute(node);
if (!queue.length) { if (!--len && cb) {
return; return cb();
} }
if (!(queue.length % 7)) { if (!(len % 7)) {
return setTimeout(softTask, 0); return setTimeout(softTask, 0);
} else { } else {
return softTask(); return softTask();
} }
}; };
len = nodes.length; len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask(); return softTask();
}, },
addCallback: function(e) { addCallback: function(e) {

View File

@ -818,7 +818,7 @@
Callbacks.prototype.push = function(_arg) { Callbacks.prototype.push = function(_arg) {
var cb, name; var cb, name;
name = _arg.name, cb = _arg.cb; name = _arg.name, cb = _arg.cb;
return this.name = cb; return this[name] = cb;
}; };
Callbacks.prototype.clean = function() { Callbacks.prototype.clean = function() {
@ -831,16 +831,15 @@
}; };
Callbacks.prototype.rm = function(name) { Callbacks.prototype.rm = function(name) {
return delete this.name; return delete this[name];
}; };
Callbacks.prototype.execute = function(target) { Callbacks.prototype.execute = function(node) {
var cb, err, errors, name; var err, errors, name;
for (name in this) { for (name in this) {
cb = this[name];
if (this.hasOwnProperty(name)) { if (this.hasOwnProperty(name)) {
try { try {
cb.call(target); this[name].call(node);
} catch (_error) { } catch (_error) {
err = _error; err = _error;
if (!errors) { if (!errors) {
@ -12545,43 +12544,32 @@
} }
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var len, node; var cb, i, node;
len = nodes.length; i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) { while (node = nodes[i++]) {
klass.callback.execute(node); cb.execute(node);
} }
}, },
callbackNodesDB: function(klass, nodes, cb) { callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask; var callbacks, errors, len, softTask;
queue = [];
errors = null; errors = null;
func = function(node) { len = 0;
klass.callback.execute(node); callbacks = klass.callbacks;
if (!queue.length) {
if (cb) {
return cb();
}
}
};
softTask = function() { softTask = function() {
var node; var node;
node = queue.shift(); node = nodes.shift();
func(node); callbacks.execute(node);
if (!queue.length) { if (!--len && cb) {
return; return cb();
} }
if (!(queue.length % 7)) { if (!(len % 7)) {
return setTimeout(softTask, 0); return setTimeout(softTask, 0);
} else { } else {
return softTask(); return softTask();
} }
}; };
len = nodes.length; len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask(); return softTask();
}, },
addCallback: function(e) { addCallback: function(e) {

View File

@ -229,40 +229,28 @@ Main =
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
callbackNodes: (klass, nodes) -> callbackNodes: (klass, nodes) ->
# get the nodes' length only once i = 0
len = nodes.length cb = klass.callbacks
while node = nodes[i++] while node = nodes[i++]
klass.callback.execute node cb.execute node
return return
callbackNodesDB: (klass, nodes, cb) -> callbackNodesDB: (klass, nodes, cb) ->
queue = []
errors = null errors = null
len = 0
func = (node) -> {callbacks} = klass
klass.callback.execute node
# finish
unless queue.length
cb() if cb
softTask = -> softTask = ->
node = queue.shift() node = nodes.shift()
func node callbacks.execute node
return unless queue.length return cb() if not --len and cb
unless queue.length % 7 unless len % 7
setTimeout softTask, 0 setTimeout softTask, 0
else else
softTask() softTask()
# get the nodes' length only once len = nodes.length
len = nodes.length
i = 0
while i < len
node = nodes[i++]
queue.push node
softTask() softTask()
addCallback: (e) -> addCallback: (e) ->

View File

@ -1,16 +1,16 @@
class Callbacks class Callbacks
push: ({name, cb}) -> @name = cb push: ({name, cb}) -> @[name] = cb
clean: -> clean: ->
@rm name for name of @ when @hasOwnProperty name @rm name for name of @ when @hasOwnProperty name
return return
rm: (name) -> delete @name rm: (name) -> delete @[name]
execute: (target) -> execute: (node) ->
for name, cb of @ when @hasOwnProperty name for name of @ when @hasOwnProperty name
try try
cb.call target @[name].call node
catch err catch err
errors = [] unless errors errors = [] unless errors
errors.push errors.push