We don't need an entire method for a set of code we only use once

This commit is contained in:
Zixaphir 2014-01-15 15:25:57 -07:00
parent 56397d7ba2
commit 9e6e9686e6
5 changed files with 18 additions and 34 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.3.2 - 2014-01-14
* 4chan X - Version 1.3.2 - 2014-01-15
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -22,7 +22,7 @@
// ==/UserScript==
/*
* 4chan X - Version 1.3.2 - 2014-01-14
* 4chan X - Version 1.3.2 - 2014-01-15
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -805,16 +805,6 @@
};
})();
$.remove = function(arr, value) {
var i;
i = arr.indexOf(value);
if (i === -1) {
return false;
}
arr.splice(i, 1);
return true;
};
$$ = function(selector, root) {
if (root == null) {
root = d.body;
@ -1624,9 +1614,13 @@
};
SimpleDict.prototype.rm = function(key) {
var i;
key = "" + key;
if ($.remove(this.keys, key)) {
return delete this[key];
if ((i = this.keys.indexOf(key)) !== -1) {
this.keys.splice(i, 1);
if ($.remove(this.keys, key)) {
return delete this[key];
}
}
};

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.3.2 - 2014-01-14
* 4chan X - Version 1.3.2 - 2014-01-15
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -810,16 +810,6 @@
};
})();
$.remove = function(arr, value) {
var i;
i = arr.indexOf(value);
if (i === -1) {
return false;
}
arr.splice(i, 1);
return true;
};
$$ = function(selector, root) {
if (root == null) {
root = d.body;
@ -1630,9 +1620,13 @@
};
SimpleDict.prototype.rm = function(key) {
var i;
key = "" + key;
if ($.remove(this.keys, key)) {
return delete this[key];
if ((i = this.keys.indexOf(key)) !== -1) {
this.keys.splice(i, 1);
if ($.remove(this.keys, key)) {
return delete this[key];
}
}
};

View File

@ -404,11 +404,5 @@ $.set = do ->
return
<% } %>
$.remove = (arr, value) ->
i = arr.indexOf value
return false if i is -1
arr.splice i, 1
true
$$ = (selector, root=d.body) ->
[root.querySelectorAll(selector)...]

View File

@ -9,6 +9,8 @@ class SimpleDict
rm: (key) ->
key = "#{key}"
delete @[key] if $.remove @keys, key
if (i = @keys.indexOf key) isnt -1
@keys.splice i, 1
delete @[key] if $.remove @keys, key
forEach: (fn) -> fn @[key] for key in [@keys...]