react-accio
Advanced tools
Comparing version 2.0.0-next.1 to 2.0.0-next.2
@@ -1,2 +0,2 @@ | ||
export { default as Accio } from './lib/CachedAccio'; | ||
export { AccioCacheProvider } from './lib/AccioCacheContext'; | ||
var t,e=require("react"),r=(t=require("hoist-non-react-statics"))&&"object"==typeof t&&"default"in t?t.default:t;function o(t){return t.then(function(t){return[null,t]}).catch(function(t){return[t]})}function n(t,e){return o(fetch(t,e)).then(function(t){var e=t[0],r=t[1];if(e)throw new Error("Accio error: "+e.message);if(!1===r.ok)throw new Error("Accio failed to fetch: "+r.url+" "+r.status+" ("+r.statusText+")");return o(r.json())}).then(function(t){var e=t[0],r=t[1];if(e)throw new Error("Error parsing response to json: "+e.message);return r})}var i,s,c={resolver:n,method:"GET"},a={};function p(t,e){var r=t;return e.body&&(r+=JSON.stringify(e.body)),r}Object.defineProperties(a,{resolver:(i=c,s="resolver",{get:function(){return i[s]},set:function(t){if("function"!=typeof t)throw new TypeError("Expected resolver to be a function. But instead got "+typeof t+". Check your "+s+" assignment to Accio defaults.");i[s]=t}}),method:{get:function(){return c.method},set:function(t){if(!["GET","POST"].includes(t))throw new TypeError("Invalid method "+t+". Only GET & POST are supported. Check your method assignment to Accio defaults.");c.method=t}}});var u=e.createContext(null),h=u.Provider,l=u.Consumer,f=function(t){function r(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];t.apply(this,e),this.cache=function(t){if("memory"===t)return new Map;if("localStorage"===t)throw new Error("Local storage cache support is incomplete. Please use memory in the meantime.");throw new Error("Unknown AccioCache storage type :/")}(this.props.use)}return t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r,r.prototype.render=function(){return e.createElement(h,{value:this.cache},this.props.children)},r}(e.Component);f.defaultProps={use:"memory"};var d=l,m=new Set(["children","url","context","defer","ignoreCache","onComplete","onError","onShowLoading","onStartFetching","timeout","_cache"]);function y(t){for(var e={},r=Object.keys(t),o=0;o<r.length;o++){var n=r[o];m.has(n)||(e[n]=t[n])}return e}var v={PRELOAD_ERROR:-1,IDLE:0,PRELOADING:1,PRELOADED:2},E=function(t){function e(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];t.apply(this,e),this.state={loading:!1,response:null,error:null,trigger:this.doWork.bind(this)},this.preloadStatus=v.IDLE,this.preloadError=null}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.preload=function(){var t=this;return Promise.resolve().then(function(){if(t.props._cache)return t.preloadStatus<v.PRELOADING?(t.preloadStatus=v.PRELOADING,o(t.doFetch.call(t)).then(function(e){var r=e[0],o=e[1];return r?(t.preloadStatus=v.PRELOAD_ERROR,void(t.preloadError=r)):(t.preloadStatus=v.PRELOADED,o)})):void 0;console.warn("Preloading without cache is not supported. This can be fixed by wrapping your app with <AccioCacheProvider />.")})},e.prototype.componentDidMount=function(){!0!==this.props.defer&&this.doWork.call(this)},e.prototype.componentWillUnmount=function(){this.timer&&clearTimeout(this.timer)},e.prototype.componentDidUpdate=function(t){var e=this.props.fetchKey;e&&e(this.props)!==e(t)&&this.doWork.call(this)},e.prototype.doWork=function(){var t=this,e=this.props,r=e._cache,n=e.onStartFetching,i=e.timeout,s=p(e.url,y(this.props));if(!r||this.preloadStatus!==v.PRELOADED)return"number"==typeof i?this.timer=setTimeout(this.setLoading.bind(this,!0),i):this.setLoading.call(this,!0),"function"==typeof n&&n(),o(this.doFetch.call(this)).then(function(e){var r=e[0],o=e[1];r&&t.setError.call(t,r),t.timer&&clearTimeout(t.timer),t.setLoading.call(t,!1),t.setResponse.call(t,o)});var c=r.get(s);this.setResponse.call(this,c)},e.prototype.doFetch=function(){var t=this.props,r=t._cache,o=t.context,n=t.ignoreCache,i=t.url,s=e.defaults.resolver,c=y(this.props),a=function(){return s(i,c,o)};if(r&&!1===n){var u=p(i,c);if(r.has(u))return Promise.resolve(r.get(u));var h=a();return r.set(u,h),h.then(function(t){return r.set(u,t),t}).catch(function(t){throw r.delete(u),t})}return a()},e.prototype.setLoading=function(t){"function"==typeof this.props.onShowLoading&&this.props.onShowLoading(),this.setState({loading:t})},e.prototype.setResponse=function(t){"function"==typeof this.props.onComplete&&this.props.onComplete(t),this.setState({response:t})},e.prototype.setError=function(t){"function"==typeof this.props.onError&&this.props.onError(t),this.setState({error:t})},e.prototype.render=function(){return this.props.children(this.state)},e}(e.Component);E.defaults=a,E.defaultProps={defer:!1,ignoreCache:!1,context:{},method:E.defaults.method};var g=function(t){function r(){t.apply(this,arguments)}return t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r,r.prototype.renderChild=function(t){var r=this.props,o=r.children,n=r.forwardedRef,i=function(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&-1===e.indexOf(o)&&(r[o]=t[o]);return r}(r,["children","forwardedRef"]);return e.createElement(E,Object.assign({},i,{ref:n,_cache:t}),o)},r.prototype.render=function(){return e.createElement(d,null,this.renderChild.bind(this))},r}(e.Component),w=e.forwardRef(function(t,r){return e.createElement(g,Object.assign({},t,{forwardedRef:r}))});r(w,E),exports.Accio=w,exports.defaultResolver=n,exports.AccioCacheProvider=f; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-accio", | ||
"version": "2.0.0-next.1", | ||
"version": "2.0.0-next.2", | ||
"description": "Declaratively fetch multiple APIs with a single React component.", | ||
"source": "src/index.js", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"unpkg": "dist/index.umd.js", | ||
"keywords": [ | ||
@@ -22,13 +25,7 @@ "react", | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.3", | ||
"hoist-non-react-statics": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/plugin-proposal-class-properties": "^7.4.0", | ||
"@babel/plugin-transform-runtime": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/plugin-transform-react-jsx": "^7.3.0", | ||
"babel-jest": "^24.7.1", | ||
@@ -38,2 +35,3 @@ "flow-bin": "^0.78.0", | ||
"jest-dom": "^3.1.3", | ||
"microbundle": "^0.11.0", | ||
"react": "^16.8.6", | ||
@@ -44,5 +42,7 @@ "react-dom": "^16.8.6", | ||
"scripts": { | ||
"build": "babel src -d dist --ignore \"**/__tests__/**/*.js\"", | ||
"dev": "rollup -c -w", | ||
"build": "microbundle --jsx React.createElement", | ||
"dev": "microbundle watch", | ||
"test": "jest", | ||
"pretest": "yarn build", | ||
"prepublish": "yarn build", | ||
"flow": "flow" | ||
@@ -49,0 +49,0 @@ }, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
40252
2
10
9
65
3
4
- Removed@babel/runtime@^7.4.3
- Removed@babel/runtime@7.26.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)