diff options
author | obscuren <geffobscura@gmail.com> | 2014-09-14 06:13:47 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-09-14 06:13:47 +0800 |
commit | 91ca5d724e1c65a7d9725b65ea0f003161301f63 (patch) | |
tree | 6d96b68fea31b9add6cc58a97dd09c0d6f3d55b5 /ethereal/assets/ext | |
parent | 893e9256a0f48b8fd45f29717145a4df23a3a799 (diff) | |
download | go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar.gz go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar.bz2 go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar.lz go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar.xz go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.tar.zst go-tangerine-91ca5d724e1c65a7d9725b65ea0f003161301f63.zip |
Reworked filters
Diffstat (limited to 'ethereal/assets/ext')
-rw-r--r-- | ethereal/assets/ext/filter.js | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/ethereal/assets/ext/filter.js b/ethereal/assets/ext/filter.js index 6d6ec8748..bc6a93144 100644 --- a/ethereal/assets/ext/filter.js +++ b/ethereal/assets/ext/filter.js @@ -1,31 +1,49 @@ +var ethx = { + prototype: Object, + + watch: function(options) { + return new Filter(options); + }, + + note: function() { + var args = Array.prototype.slice.call(arguments, 0); + var o = [] + for(var i = 0; i < args.length; i++) { + o.push(args[i].toString()) + } + + eth.notef(o); + }, +}; + var Filter = function(options) { - this.callbacks = {}; - this.seed = Math.floor(Math.random() * 1000000); + this.callbacks = []; this.options = options; if(options === "chain") { - eth.registerFilterString(options, this.seed); + this.id = eth.newFilterString(options); } else if(typeof options === "object") { - eth.registerFilter(options, this.seed); + this.id = eth.newFilter(options); } }; Filter.prototype.changed = function(callback) { - var cbseed = Math.floor(Math.random() * 1000000); - eth.registerFilterCallback(this.seed, cbseed); + this.callbacks.push(callback); var self = this; - message.connect(function(messages, seed, callbackSeed) { - if(seed == self.seed && callbackSeed == cbseed) { - callback.call(self, messages); + message.connect(function(messages, id) { + if(id == self.id) { + for(var i = 0; i < self.callbacks.length; i++) { + self.callbacks[i].call(self, messages); + } } }); }; Filter.prototype.uninstall = function() { - eth.uninstallFilter(this.seed) + eth.uninstallFilter(this.id) } Filter.prototype.messages = function() { - return JSON.parse(eth.messages(this.options)) + return eth.messages(this.id) } |