picked watch change

This commit is contained in:
Fabian Vogelsteller 2015-03-31 13:16:07 +02:00
parent dc0f2318bf
commit 2215e7c3af
7 changed files with 79 additions and 28 deletions

31
dist/web3-light.js vendored
View File

@ -2106,7 +2106,8 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this;
var self = this,
requestmanager = RequestManager.getInstance();
var onMessage = function (error, messages) {
if (error) {
@ -2123,7 +2124,12 @@ Filter.prototype.watch = function (callback) {
});
};
RequestManager.getInstance().startPolling({
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
}
requestmanager.startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -2135,12 +2141,23 @@ Filter.prototype.stopWatching = function () {
this.callbacks = [];
};
Filter.prototype.get = function () {
var logs = this.implementation.getLogs(this.filterId);
Filter.prototype.get = function (callback) {
var self = this;
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
if(utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
});
} else {
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
}
};
module.exports = Filter;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

31
dist/web3.js vendored
View File

@ -2106,7 +2106,8 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this;
var self = this,
requestmanager = RequestManager.getInstance();
var onMessage = function (error, messages) {
if (error) {
@ -2123,7 +2124,12 @@ Filter.prototype.watch = function (callback) {
});
};
RequestManager.getInstance().startPolling({
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
}
requestmanager.startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -2135,12 +2141,23 @@ Filter.prototype.stopWatching = function () {
this.callbacks = [];
};
Filter.prototype.get = function () {
var logs = this.implementation.getLogs(this.filterId);
Filter.prototype.get = function (callback) {
var self = this;
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
if(utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
});
} else {
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
}
};
module.exports = Filter;

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -69,7 +69,8 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this;
var self = this,
requestmanager = RequestManager.getInstance();
var onMessage = function (error, messages) {
if (error) {
@ -86,7 +87,12 @@ Filter.prototype.watch = function (callback) {
});
};
RequestManager.getInstance().startPolling({
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
}
requestmanager.startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -98,12 +104,23 @@ Filter.prototype.stopWatching = function () {
this.callbacks = [];
};
Filter.prototype.get = function () {
var logs = this.implementation.getLogs(this.filterId);
Filter.prototype.get = function (callback) {
var self = this;
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
if(utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
});
} else {
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;
});
}
};
module.exports = Filter;