react-transporter
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -146,2 +146,5 @@ 'use strict'; | ||
// Set cache | ||
_this.cache = {}; | ||
// Bind load method | ||
@@ -183,4 +186,5 @@ _this.handleLoad = _this.handleLoad.bind(_this); | ||
}; | ||
var cache = _this2.getCacheProvider(); | ||
loader.request(load, _this2.context.store.dispatch); | ||
loader.request({ load: load, cache: cache }, _this2.context.store.dispatch); | ||
}); | ||
@@ -218,4 +222,5 @@ } | ||
}; | ||
var cache = _this3.getCacheProvider(); | ||
loader.request(load, _this3.context.store.dispatch); | ||
loader.request({ load: load, cache: cache }, _this3.context.store.dispatch); | ||
}); | ||
@@ -241,3 +246,6 @@ | ||
if (loader.shouldUpdate && !_this4.state[key].loading) { | ||
if (loader.shouldUpdate(_this4.state[key], nextProps, nextContext.store.getState())) { | ||
if (loader.shouldUpdate({ | ||
info: _this4.state[key], | ||
cache: _this4.getCacheProvider() | ||
}, nextProps, nextContext.store.getState())) { | ||
_this4.setRequestState(key, 'block', null); | ||
@@ -248,3 +256,5 @@ | ||
}; | ||
loader.request(load, _this4.context.store.dispatch); | ||
var cache = _this4.getCacheProvider(); | ||
loader.request({ load: load, cache: cache }, _this4.context.store.dispatch); | ||
} | ||
@@ -289,2 +299,16 @@ } | ||
}, { | ||
key: 'getCacheProvider', | ||
value: function getCacheProvider() { | ||
var _this6 = this; | ||
return { | ||
get: function get(cacheKey) { | ||
return _this6.cache[cacheKey]; | ||
}, | ||
set: function set(cacheKey, cacheValue) { | ||
_this6.cache[cacheKey] = cacheValue; | ||
} | ||
}; | ||
} | ||
}, { | ||
key: 'setRequestState', | ||
@@ -325,3 +349,3 @@ value: function setRequestState(key, loading, error) { | ||
value: function render() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -337,3 +361,3 @@ var config = this.getConfig(); | ||
var load = function load(promise, loadOptions) { | ||
if (_this6.state.loading[key]) { | ||
if (_this7.state.loading[key]) { | ||
// eslint-disable-next-line no-console | ||
@@ -343,9 +367,10 @@ console.error('Resource ' + name + ' ' + key + ' is already loading.'); | ||
// Start request | ||
_this6.setRequestState(key, loadOptions && loadOptions.showWhileLoading ? 'show' : 'block'); | ||
_this7.setRequestState(key, loadOptions && loadOptions.showWhileLoading ? 'show' : 'block'); | ||
_this6.handleLoad(key, promise, false); | ||
_this7.handleLoad(key, promise, false); | ||
} | ||
}; | ||
var cache = _this7.getCacheProvider(); | ||
loaderProps[key] = _extends({}, _this6.state[key], loader.props(load, _this6.context.store.dispatch)); | ||
loaderProps[key] = _extends({}, _this7.state[key], loader.props({ load: load, cache: cache }, _this7.context.store.dispatch)); | ||
} | ||
@@ -374,4 +399,4 @@ }); | ||
Object.keys(this.state).forEach(function (key) { | ||
if (_this6.state[key].error) { | ||
errors[key] = _this6.state[key].error; | ||
if (_this7.state[key].error) { | ||
errors[key] = _this7.state[key].error; | ||
} | ||
@@ -378,0 +403,0 @@ }); |
@@ -26,7 +26,6 @@ 'use strict'; | ||
var schemaBody = schema.loc.source.body; | ||
// TODO integrate cache into (load, cache) => function | ||
var timeout = null; | ||
return { | ||
request: function request(load, dispatch) { | ||
request: function request(_ref, dispatch) { | ||
var load = _ref.load; | ||
return loaderOptions && loaderOptions.skip ? load(new Promise(function (resolve) { | ||
@@ -36,3 +35,5 @@ return resolve(); | ||
}, | ||
props: function props(load, dispatch) { | ||
props: function props(_ref2, dispatch) { | ||
var load = _ref2.load, | ||
cache = _ref2.cache; | ||
return { | ||
@@ -56,3 +57,3 @@ refetch: function refetch() { | ||
startPolling: function startPolling(interval) { | ||
timeout = setInterval(function () { | ||
var timeout = setInterval(function () { | ||
load(dispatch((0, _createQuery2.default)(schemaBody, options), { | ||
@@ -62,12 +63,21 @@ showWhileLoading: true | ||
}, interval); | ||
cache.set('timeout', timeout); | ||
}, | ||
endPolling: function endPolling() { | ||
clearInterval(timeout); | ||
clearInterval(cache.get('timeout')); | ||
cache.set('timeout', null); | ||
} | ||
}; | ||
}, | ||
shouldReload: function shouldReload(info, props, state) { | ||
return info.startTime < state.transporter.info.lastReset; | ||
shouldReload: function shouldReload(_ref3, props, state) { | ||
var info = _ref3.info, | ||
cache = _ref3.cache; | ||
var previousVariables = cache.get('variables'); | ||
cache.set('variables', options.variables); | ||
return info.startTime < state.transporter.info.lastReset || previousVariables === options.variables; | ||
} | ||
}; | ||
} |
{ | ||
"name": "react-transporter", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"main": "./lib/index.js", | ||
@@ -48,3 +48,2 @@ "description": "React.js Redux GraphQL client", | ||
"react": ">=15", | ||
"react-async-bootstrapper": ">=1", | ||
"react-dom": ">=15", | ||
@@ -51,0 +50,0 @@ "react-redux": ">=5", |
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
97276
8
2150