falcor-http-ws-datasource
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -33,2 +33,6 @@ 'use strict'; | ||
var _q = require('q'); | ||
var _q2 = _interopRequireDefault(_q); | ||
var noop = function noop() {}; | ||
@@ -139,17 +143,89 @@ | ||
}, { | ||
key: '_monitorRequest', | ||
value: function _monitorRequest(res) { | ||
key: '_retry', | ||
value: function _retry(method, args, observer) { | ||
var _this2 = this; | ||
var res = undefined; | ||
if (method === 'get') { | ||
res = _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'get', this).apply(this, args); | ||
} else if (method === 'set') { | ||
res = _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'set', this).apply(this, args); | ||
} else if (method === 'call') { | ||
res = _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'call', this).apply(this, args); | ||
} | ||
res.subscribe(function (res) { | ||
// Recall the onError callback for logging purposes only | ||
_this2._needRetryOnErrors(method, args, res); | ||
observer.onNext(res); | ||
}, function (err) { | ||
observer.onError(err); | ||
}, function () { | ||
_this2._finishedRequest(); | ||
observer.onCompleted(); | ||
}); | ||
} | ||
}, { | ||
key: '_needRetryOnErrors', | ||
value: function _needRetryOnErrors(method, args, node) { | ||
var $type = node ? node.$type : null; | ||
if ($type === 'error') { | ||
return this.onError(method, args, node.value); | ||
} else if (node && typeof node === 'object') { | ||
var needRetries = []; | ||
for (var key in node) { | ||
needRetries.push(this._needRetryOnErrors(method, args, node[key])); | ||
} | ||
return _q2['default'].all(needRetries).then(function (retries) { | ||
return retries.reduce(function (r, needRetry) { | ||
return r || needRetry; | ||
}); | ||
}); | ||
} | ||
return _q2['default'].fcall(function () { | ||
return false; | ||
}); | ||
} | ||
}, { | ||
key: '_monitorRequest', | ||
value: function _monitorRequest(method, args, res) { | ||
var _this3 = this; | ||
this._fireRequest(); | ||
var observable = Observable.create(function (observer) { | ||
var validateNeedRetry = _q2['default'].defer(); | ||
res.subscribe(function (res) { | ||
return observer.onNext(res); | ||
_this3._needRetryOnErrors(method, args, res).then(function (needRetry) { | ||
if (needRetry) { | ||
_this3._retry(method, args, observer); | ||
} else { | ||
observer.onNext(res); | ||
} | ||
validateNeedRetry.resolve(needRetry); | ||
}); | ||
}, function (err) { | ||
_this2.onError(err); | ||
observer.onError(err); | ||
_this3.onError(method, args, err).then(function (needRetry) { | ||
if (needRetry) { | ||
_this3._retry(method, args, observer); | ||
} else { | ||
observer.onError(err); | ||
} | ||
validateNeedRetry.resolve(needRetry); | ||
}); | ||
}, function () { | ||
_this2._finishedRequest(); | ||
observer.onCompleted(); | ||
validateNeedRetry.promise.then(function (needRetry) { | ||
if (!needRetry) { | ||
_this3._finishedRequest(); | ||
observer.onCompleted(); | ||
} | ||
}); | ||
}); | ||
@@ -170,3 +246,3 @@ | ||
// returns an Observable if you wanted to map/filter/reduce/etc | ||
return this._monitorRequest(_get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'get', this).apply(this, args)); | ||
return this._monitorRequest('get', args, _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'get', this).apply(this, args)); | ||
} | ||
@@ -181,3 +257,3 @@ }, { | ||
// returns an Observable if you wanted to map/filter/reduce/etc | ||
return this._monitorRequest(_get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'set', this).apply(this, args)); | ||
return this._monitorRequest('set', args, _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'set', this).apply(this, args)); | ||
} | ||
@@ -192,3 +268,3 @@ }, { | ||
// returns an Observable if you wanted to map/filter/reduce/etc | ||
return this._monitorRequest(_get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'call', this).apply(this, args)); | ||
return this._monitorRequest('call', args, _get(Object.getPrototypeOf(FalcorHttpPullWebSocketPushDataSource.prototype), 'call', this).apply(this, args)); | ||
} | ||
@@ -195,0 +271,0 @@ }, { |
{ | ||
"name": "falcor-http-ws-datasource", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Falcor HTTP and WebSocket datasource", | ||
@@ -21,3 +21,4 @@ "homepage": "", | ||
"socket.io-client": "^1.4.8", | ||
"uuid": "^2.0.1" | ||
"uuid": "^2.0.1", | ||
"q": "^1.4.1" | ||
}, | ||
@@ -24,0 +25,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14351
284
4