Comparing version 0.2.0 to 1.0.0
{ | ||
"index.js": { | ||
"bundled": 2691, | ||
"minified": 1214, | ||
"bundled": 2694, | ||
"minified": 1217, | ||
"gzipped": 543, | ||
@@ -12,3 +12,3 @@ "treeshaked": { | ||
"webpack": { | ||
"code": 1785 | ||
"code": 1788 | ||
} | ||
@@ -18,6 +18,6 @@ } | ||
"index.cjs.js": { | ||
"bundled": 5848, | ||
"minified": 3204, | ||
"bundled": 6006, | ||
"minified": 3284, | ||
"gzipped": 1250 | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react");function e(r,e){var t;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(t=function(r,e){if(!r)return;if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);"Object"===t&&r.constructor&&(t=r.constructor.name);if("Map"===t||"Set"===t)return Array.from(r);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return n(r,e)}(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=r[Symbol.iterator]()).next.bind(t)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var t=[],o=function(r,e){return r.length===e.length&&r.every((function(r,n){return r===e[n]}))};function i(r,n,t,i,a){void 0===i&&(i=0),void 0===a&&(a=!1);for(var u,f=e(n);!(u=f()).done;){var l=u.value;if(o(t,l.args)){if(a)return;if(l.error)throw l.error;if(l.response)return l.response;throw l.promise}}var c={args:t,promise:r.apply(void 0,t).then((function(r){return c.response=null==r||r})).catch((function(r){return c.error=r})).then((function(){i>0&&setTimeout((function(){var r=n.indexOf(c);-1!==r&&n.splice(r,1)}),i)}))};if(n.push(c),!a)throw c.promise}function a(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),t=1;t<e;t++)n[t-1]=arguments[t];if(void 0===n)r.splice(0,r.length);else{var i=r.find((function(r){return o(n,r.args)}));if(i){var a=r.indexOf(i);-1!==a&&r.splice(a,1)}}}function u(e,n){return r.useMemo((function(){return i(e,t,n,u.lifespan)}),n)}u.lifespan=0,u.clear=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return a.apply(void 0,[t].concat(e))},u.preload=function(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];i(r,t,n,u.lifespan,!0)},u.peek=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return null==(r=t.find((function(r){return o(n,r.args)})))?void 0:r.response},exports.createAsset=function(r,e){void 0===e&&(e=0);var n=[];return{read:function(){for(var t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];return i(r,n,o,e)},preload:function(){for(var t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];i(r,n,o,e,!0)},clear:function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];return a.apply(void 0,[n].concat(e))},peek:function(){for(var r,e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return null==(r=n.find((function(r){return o(t,r.args)})))?void 0:r.response}}},exports.useAsset=u; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react");function e(r,e){var t;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(t=function(r,e){if(!r)return;if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);"Object"===t&&r.constructor&&(t=r.constructor.name);if("Map"===t||"Set"===t)return Array.from(r);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return n(r,e)}(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=r[Symbol.iterator]()).next.bind(t)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var t=[],o=function(r,e){return r.length===e.length&&r.every((function(r,n){return r===e[n]}))};function i(r,n,t,i,a){void 0===i&&(i=0),void 0===a&&(a=!1);for(var u,f=e(n);!(u=f()).done;){var l=u.value;if(o(t,l.args)){if(a)return;if(l.error)throw l.error;if(l.response)return l.response;throw l.promise}}var c={args:t,promise:r.apply(void 0,t).then((function(r){return c.response=null==r||r})).catch((function(r){return c.error=r})).then((function(){i>0&&setTimeout((function(){var r=n.indexOf(c);-1!==r&&n.splice(r,1)}),i)}))};if(n.push(c),!a)throw c.promise}function a(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),t=1;t<e;t++)n[t-1]=arguments[t];if(void 0===n)r.splice(0,r.length);else{var i=r.find((function(r){return o(n,r.args)}));if(i){var a=r.indexOf(i);-1!==a&&r.splice(a,1)}}}function u(e){for(var n=arguments.length,o=new Array(n>1?n-1:0),a=1;a<n;a++)o[a-1]=arguments[a];return r.useMemo((function(){return i(e,t,o,u.lifespan)}),o)}u.lifespan=0,u.clear=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return a.apply(void 0,[t].concat(e))},u.preload=function(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];i(r,t,n,u.lifespan,!0)},u.peek=function(){for(var r,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return null==(r=t.find((function(r){return o(n,r.args)})))?void 0:r.response},exports.createAsset=function(r,e){void 0===e&&(e=0);var n=[];return{read:function(){for(var t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];return i(r,n,o,e)},preload:function(){for(var t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];i(r,n,o,e,!0)},clear:function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];return a.apply(void 0,[n].concat(e))},peek:function(){for(var r,e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return null==(r=n.find((function(r){return o(t,r.args)})))?void 0:r.response}}},exports.useAsset=u; |
@@ -12,3 +12,3 @@ declare type PromiseFn<Response, Args extends any[]> = (...args: Args) => Promise<Response>; | ||
}; | ||
declare function useAsset<Response, Args extends any[]>(fn: PromiseFn<Response, Args>, args: Args): Response; | ||
declare function useAsset<Response, Args extends any[]>(fn: PromiseFn<Response, Args>, ...args: Args): Response; | ||
declare namespace useAsset { | ||
@@ -15,0 +15,0 @@ var lifespan: number; |
@@ -1,1 +0,1 @@ | ||
import{useMemo as e}from"react";const r=[],n=(e,r)=>e.length===r.length&&e.every((e,n)=>e===r[n]);function o(e,r,o,s=0,t=!1){for(const e of r)if(n(o,e.args)){if(t)return;if(e.error)throw e.error;if(e.response)return e.response;throw e.promise}const i={args:o,promise:e(...o).then(e=>i.response=null==e||e).catch(e=>i.error=e).then(()=>{s>0&&setTimeout(()=>{const e=r.indexOf(i);-1!==e&&r.splice(e,1)},s)})};if(r.push(i),!t)throw i.promise}function s(e,...r){if(void 0===r)e.splice(0,e.length);else{const o=e.find(e=>n(r,e.args));if(o){const r=e.indexOf(o);-1!==r&&e.splice(r,1)}}}function t(e,r=0){const t=[];return{read:(...n)=>o(e,t,n,r),preload:(...n)=>{o(e,t,n,r,!0)},clear:(...e)=>s(t,...e),peek:(...e)=>{var r;return null==(r=t.find(r=>n(e,r.args)))?void 0:r.response}}}function i(n,s){return e(()=>o(n,r,s,i.lifespan),s)}i.lifespan=0,i.clear=(...e)=>s(r,...e),i.preload=(e,...n)=>{o(e,r,n,i.lifespan,!0)},i.peek=(...e)=>{var o;return null==(o=r.find(r=>n(e,r.args)))?void 0:o.response};export{t as createAsset,i as useAsset}; | ||
import{useMemo as e}from"react";const r=[],n=(e,r)=>e.length===r.length&&e.every((e,n)=>e===r[n]);function o(e,r,o,s=0,t=!1){for(const e of r)if(n(o,e.args)){if(t)return;if(e.error)throw e.error;if(e.response)return e.response;throw e.promise}const i={args:o,promise:e(...o).then(e=>i.response=null==e||e).catch(e=>i.error=e).then(()=>{s>0&&setTimeout(()=>{const e=r.indexOf(i);-1!==e&&r.splice(e,1)},s)})};if(r.push(i),!t)throw i.promise}function s(e,...r){if(void 0===r)e.splice(0,e.length);else{const o=e.find(e=>n(r,e.args));if(o){const r=e.indexOf(o);-1!==r&&e.splice(r,1)}}}function t(e,r=0){const t=[];return{read:(...n)=>o(e,t,n,r),preload:(...n)=>{o(e,t,n,r,!0)},clear:(...e)=>s(t,...e),peek:(...e)=>{var r;return null==(r=t.find(r=>n(e,r.args)))?void 0:r.response}}}function i(n,...s){return e(()=>o(n,r,s,i.lifespan),s)}i.lifespan=0,i.clear=(...e)=>s(r,...e),i.preload=(e,...n)=>{o(e,r,n,i.lifespan,!0)},i.peek=(...e)=>{var o;return null==(o=r.find(r=>n(e,r.args)))?void 0:o.response};export{t as createAsset,i as useAsset}; |
{ | ||
"name": "use-asset", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "A data fetching strategy for React Suspense", | ||
@@ -39,31 +39,31 @@ "main": "dist/index.cjs", | ||
"devDependencies": { | ||
"@babel/core": "7.11.0", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-transform-modules-commonjs": "7.10.4", | ||
"@babel/plugin-transform-parameters": "7.10.5", | ||
"@babel/plugin-transform-runtime": "7.11.0", | ||
"@babel/plugin-transform-template-literals": "7.10.5", | ||
"@babel/preset-env": "7.11.0", | ||
"@babel/preset-react": "7.10.4", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@types/jest": "^26.0.8", | ||
"@types/node": "^14.6.0", | ||
"@types/react": "^16.9.46", | ||
"@types/react-dom": "^16.9.8", | ||
"@types/react-test-renderer": "^16.9.3", | ||
"@typescript-eslint/eslint-plugin": "^3.7.1", | ||
"@typescript-eslint/parser": "^3.7.1", | ||
"husky": "^4.2.5", | ||
"lint-staged": "^10.2.11", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.26.10", | ||
"@babel/core": "7.12.10", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-transform-modules-commonjs": "7.12.1", | ||
"@babel/plugin-transform-parameters": "7.12.1", | ||
"@babel/plugin-transform-runtime": "7.12.10", | ||
"@babel/plugin-transform-template-literals": "7.12.1", | ||
"@babel/preset-env": "7.12.11", | ||
"@babel/preset-react": "7.12.10", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@rollup/plugin-babel": "^5.2.2", | ||
"@rollup/plugin-node-resolve": "^11.1.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.21", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/react-test-renderer": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.13.0", | ||
"@typescript-eslint/parser": "^4.13.0", | ||
"husky": "^4.3.8", | ||
"lint-staged": "^10.5.3", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.36.2", | ||
"rollup-plugin-size-snapshot": "^0.12.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typescript": "^3.9.7" | ||
"typescript": "^4.1.3" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.13" | ||
"react": ">=17.0" | ||
} | ||
} |
@@ -80,3 +80,3 @@ <p align="left"> | ||
function Post({ id }) { | ||
const { by, title } = useAsset(fn, [id]) | ||
const { by, title } = useAsset(fn, id) | ||
return <div>{title} by {by}</div> | ||
@@ -97,3 +97,3 @@ } | ||
useAsset.lifespan = 15000 | ||
useAsset(promiseFn, ["/image.png"]) | ||
useAsset(promiseFn, "/image.png") | ||
// Clear all cached entries | ||
@@ -100,0 +100,0 @@ useAsset.clear() |
@@ -84,3 +84,3 @@ import { useMemo } from 'react' | ||
function useAsset<Response, Args extends any[]>(fn: PromiseFn<Response, Args>, args: Args): Response { | ||
function useAsset<Response, Args extends any[]>(fn: PromiseFn<Response, Args>, ...args: Args): Response { | ||
return useMemo( | ||
@@ -87,0 +87,0 @@ () => handleAsset(fn, globalCache as PromiseCache<Response, Args>[], args, useAsset.lifespan), |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
176043
209
2