@washingtonpost/red-react-lib
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -6,3 +6,3 @@ {"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/index.js": {"path":"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/index.js","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"6ad992d2a497a71026a3830cf02ac4c2f79f633a"} | ||
,"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useRouter.js": {"path":"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useRouter.js","statementMap":{"0":{"start":{"line":5,"column":23},"end":{"line":8,"column":1}},"1":{"start":{"line":11,"column":19},"end":{"line":11,"column":30}},"2":{"start":{"line":12,"column":21},"end":{"line":12,"column":34}},"3":{"start":{"line":13,"column":20},"end":{"line":13,"column":32}},"4":{"start":{"line":14,"column":18},"end":{"line":14,"column":33}},"5":{"start":{"line":18,"column":4},"end":{"line":39,"column":51}},"6":{"start":{"line":19,"column":22},"end":{"line":19,"column":56}},"7":{"start":{"line":20,"column":8},"end":{"line":38,"column":9}},"8":{"start":{"line":27,"column":44},"end":{"line":27,"column":51}},"9":{"start":{"line":28,"column":27},"end":{"line":28,"column":86}},"10":{"start":{"line":28,"column":67},"end":{"line":28,"column":85}},"11":{"start":{"line":29,"column":28},"end":{"line":29,"column":51}},"12":{"start":{"line":30,"column":16},"end":{"line":30,"column":42}}},"fnMap":{"0":{"name":"useRouter","decl":{"start":{"line":10,"column":16},"end":{"line":10,"column":25}},"loc":{"start":{"line":10,"column":52},"end":{"line":40,"column":1}},"line":10},"1":{"name":"(anonymous_1)","decl":{"start":{"line":18,"column":25},"end":{"line":18,"column":26}},"loc":{"start":{"line":18,"column":31},"end":{"line":39,"column":5}},"line":18},"2":{"name":"(anonymous_2)","decl":{"start":{"line":26,"column":22},"end":{"line":26,"column":23}},"loc":{"start":{"line":26,"column":43},"end":{"line":31,"column":13}},"line":26},"3":{"name":"(anonymous_3)","decl":{"start":{"line":28,"column":57},"end":{"line":28,"column":58}},"loc":{"start":{"line":28,"column":67},"end":{"line":28,"column":85}},"line":28}},"branchMap":{"0":{"loc":{"start":{"line":10,"column":26},"end":{"line":10,"column":50}},"type":"default-arg","locations":[{"start":{"line":10,"column":36},"end":{"line":10,"column":50}}],"line":10},"1":{"loc":{"start":{"line":26,"column":26},"end":{"line":26,"column":38}},"type":"default-arg","locations":[{"start":{"line":26,"column":36},"end":{"line":26,"column":38}}],"line":26},"2":{"loc":{"start":{"line":27,"column":24},"end":{"line":27,"column":39}},"type":"default-arg","locations":[{"start":{"line":27,"column":33},"end":{"line":27,"column":39}}],"line":27},"3":{"loc":{"start":{"line":28,"column":27},"end":{"line":28,"column":86}},"type":"cond-expr","locations":[{"start":{"line":28,"column":53},"end":{"line":28,"column":54}},{"start":{"line":28,"column":57},"end":{"line":28,"column":86}}],"line":28}},"s":{"0":2,"1":3,"2":3,"3":3,"4":3,"5":3,"6":3,"7":3,"8":2,"9":2,"10":1,"11":2,"12":2},"f":{"0":3,"1":3,"2":2,"3":1},"b":{"0":[3],"1":[2],"2":[2],"3":[1,1]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"810c4b7f867f6156382ea7cf472bb9d88e13cf1a"} | ||
,"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useStorage.js": {"path":"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useStorage.js","statementMap":{"0":{"start":{"line":5,"column":21},"end":{"line":16,"column":5}},"1":{"start":{"line":6,"column":8},"end":{"line":15,"column":9}},"2":{"start":{"line":8,"column":25},"end":{"line":8,"column":45}},"3":{"start":{"line":10,"column":12},"end":{"line":10,"column":57}},"4":{"start":{"line":13,"column":12},"end":{"line":13,"column":30}},"5":{"start":{"line":14,"column":12},"end":{"line":14,"column":31}},"6":{"start":{"line":19,"column":42},"end":{"line":19,"column":91}},"7":{"start":{"line":19,"column":63},"end":{"line":19,"column":90}},"8":{"start":{"line":21,"column":4},"end":{"line":24,"column":13}},"9":{"start":{"line":22,"column":20},"end":{"line":22,"column":47}},"10":{"start":{"line":23,"column":8},"end":{"line":23,"column":27}},"11":{"start":{"line":28,"column":21},"end":{"line":40,"column":5}},"12":{"start":{"line":29,"column":8},"end":{"line":39,"column":9}},"13":{"start":{"line":31,"column":33},"end":{"line":31,"column":87}},"14":{"start":{"line":33,"column":12},"end":{"line":33,"column":62}},"15":{"start":{"line":35,"column":12},"end":{"line":35,"column":40}},"16":{"start":{"line":38,"column":12},"end":{"line":38,"column":30}},"17":{"start":{"line":42,"column":4},"end":{"line":42,"column":34}}},"fnMap":{"0":{"name":"useStorage","decl":{"start":{"line":4,"column":9},"end":{"line":4,"column":19}},"loc":{"start":{"line":4,"column":70},"end":{"line":43,"column":1}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":5,"column":21},"end":{"line":5,"column":22}},"loc":{"start":{"line":5,"column":44},"end":{"line":16,"column":5}},"line":5},"2":{"name":"(anonymous_2)","decl":{"start":{"line":19,"column":57},"end":{"line":19,"column":58}},"loc":{"start":{"line":19,"column":63},"end":{"line":19,"column":90}},"line":19},"3":{"name":"(anonymous_3)","decl":{"start":{"line":21,"column":20},"end":{"line":21,"column":21}},"loc":{"start":{"line":21,"column":26},"end":{"line":24,"column":5}},"line":21},"4":{"name":"(anonymous_4)","decl":{"start":{"line":28,"column":21},"end":{"line":28,"column":22}},"loc":{"start":{"line":28,"column":30},"end":{"line":40,"column":5}},"line":28}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":39},"end":{"line":4,"column":68}},"type":"default-arg","locations":[{"start":{"line":4,"column":49},"end":{"line":4,"column":68}}],"line":4},"1":{"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":57}},"type":"cond-expr","locations":[{"start":{"line":10,"column":26},"end":{"line":10,"column":42}},{"start":{"line":10,"column":45},"end":{"line":10,"column":57}}],"line":10},"2":{"loc":{"start":{"line":31,"column":33},"end":{"line":31,"column":87}},"type":"cond-expr","locations":[{"start":{"line":31,"column":61},"end":{"line":31,"column":79}},{"start":{"line":31,"column":82},"end":{"line":31,"column":87}}],"line":31}},"s":{"0":9,"1":6,"2":6,"3":5,"4":1,"5":1,"6":9,"7":2,"8":9,"9":4,"10":4,"11":9,"12":2,"13":2,"14":2,"15":1,"16":1,"17":9},"f":{"0":9,"1":6,"2":2,"3":4,"4":2},"b":{"0":[5],"1":[4,1],"2":[1,1]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"673428e9378fcc01f98135fdb1a9574e4415e4e9"} | ||
,"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useStorage.js": {"path":"/Users/rabolinil/Documents/WP/red-react-lib/packages/red-react-lib/src/hooks/useStorage.js","statementMap":{"0":{"start":{"line":5,"column":21},"end":{"line":16,"column":5}},"1":{"start":{"line":6,"column":8},"end":{"line":15,"column":9}},"2":{"start":{"line":8,"column":25},"end":{"line":8,"column":45}},"3":{"start":{"line":10,"column":12},"end":{"line":10,"column":57}},"4":{"start":{"line":13,"column":12},"end":{"line":13,"column":30}},"5":{"start":{"line":14,"column":12},"end":{"line":14,"column":31}},"6":{"start":{"line":19,"column":42},"end":{"line":19,"column":85}},"7":{"start":{"line":19,"column":57},"end":{"line":19,"column":84}},"8":{"start":{"line":21,"column":4},"end":{"line":24,"column":13}},"9":{"start":{"line":22,"column":20},"end":{"line":22,"column":47}},"10":{"start":{"line":23,"column":8},"end":{"line":23,"column":27}},"11":{"start":{"line":28,"column":21},"end":{"line":40,"column":5}},"12":{"start":{"line":29,"column":8},"end":{"line":39,"column":9}},"13":{"start":{"line":31,"column":33},"end":{"line":31,"column":87}},"14":{"start":{"line":33,"column":12},"end":{"line":33,"column":62}},"15":{"start":{"line":35,"column":12},"end":{"line":35,"column":40}},"16":{"start":{"line":38,"column":12},"end":{"line":38,"column":30}},"17":{"start":{"line":42,"column":4},"end":{"line":42,"column":34}}},"fnMap":{"0":{"name":"useStorage","decl":{"start":{"line":4,"column":16},"end":{"line":4,"column":26}},"loc":{"start":{"line":4,"column":77},"end":{"line":43,"column":1}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":5,"column":21},"end":{"line":5,"column":22}},"loc":{"start":{"line":5,"column":44},"end":{"line":16,"column":5}},"line":5},"2":{"name":"(anonymous_2)","decl":{"start":{"line":19,"column":51},"end":{"line":19,"column":52}},"loc":{"start":{"line":19,"column":57},"end":{"line":19,"column":84}},"line":19},"3":{"name":"(anonymous_3)","decl":{"start":{"line":21,"column":14},"end":{"line":21,"column":15}},"loc":{"start":{"line":21,"column":20},"end":{"line":24,"column":5}},"line":21},"4":{"name":"(anonymous_4)","decl":{"start":{"line":28,"column":21},"end":{"line":28,"column":22}},"loc":{"start":{"line":28,"column":30},"end":{"line":40,"column":5}},"line":28}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":46},"end":{"line":4,"column":75}},"type":"default-arg","locations":[{"start":{"line":4,"column":56},"end":{"line":4,"column":75}}],"line":4},"1":{"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":57}},"type":"cond-expr","locations":[{"start":{"line":10,"column":26},"end":{"line":10,"column":42}},{"start":{"line":10,"column":45},"end":{"line":10,"column":57}}],"line":10},"2":{"loc":{"start":{"line":31,"column":33},"end":{"line":31,"column":87}},"type":"cond-expr","locations":[{"start":{"line":31,"column":61},"end":{"line":31,"column":79}},{"start":{"line":31,"column":82},"end":{"line":31,"column":87}}],"line":31}},"s":{"0":9,"1":6,"2":6,"3":5,"4":1,"5":1,"6":9,"7":2,"8":9,"9":4,"10":4,"11":9,"12":2,"13":2,"14":2,"15":1,"16":1,"17":9},"f":{"0":9,"1":6,"2":2,"3":4,"4":2},"b":{"0":[5],"1":[4,1],"2":[1,1]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"c20e02c68cd66f1e521ad04864e9c55dcc25df0b"} | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),reactRouterDom=require("react-router-dom"),qs=_interopDefault(require("qs"));function usePrevious(e){var r=React.useRef();return React.useEffect(function(){r.current=e},[e]),r.current}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _objectSpread(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(e){_defineProperty(r,e,t[e])})}return r}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_nonIterableRest()}function _toArray(e){return _arrayWithHoles(e)||_iterableToArray(e)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var r=0,t=new Array(e.length);r<e.length;r++)t[r]=e[r];return t}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,r){var t=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(t.push(u.value),!r||t.length!==r);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return t}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var setLoading=function(e){return{result:e.result,loading:!0}};function usePromiseCallback(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,n=_slicedToArray(React.useState({}),2),o=n[0],a=n[1],u=React.useRef(0),i=React.useRef(0),c=React.useCallback(function(){t?(clearTimeout(u.current),u.current=setTimeout(function(){return a(setLoading)},t)):a(setLoading);var r=++i.current;return e.apply(void 0,arguments).then(function(e){return r===i.current&&a({result:e})}).catch(function(e){return r===i.current&&a({err:e})}).finally(function(){return r===i.current&&clearTimeout(u.current)})},r);return React.useEffect(function(){i.current=0,clearTimeout(u.current)},[]),[c,o.result,o.loading,o.err]}function usePromise(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],t=_toArray(usePromiseCallback(e,r,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0)),n=t[0],o=t.slice(1),a=React.useCallback(function(){return n.apply(void 0,_toConsumableArray(r))},[n]);return React.useEffect(function(){a.apply(void 0,_toConsumableArray(r))},[a]),[a].concat(_toConsumableArray(o))}var defaultOptions={ignoreQueryPrefix:!0,interpretNumericEntities:!0};function useRouter(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions,r=reactRouterDom.useParams(),t=reactRouterDom.useLocation(),i=reactRouterDom.useHistory(),n=reactRouterDom.useRouteMatch();return React__default.useMemo(function(){var u=qs.parse(t.search,e);return{push:i.push,replace:i.replace,pathname:t.pathname,query:u,setQuery:function(r,e){var t=(1<arguments.length&&void 0!==e?e:{}).method,n=void 0===t?"push":t,o="function"==typeof r?r:function(e){return _objectSpread({},e,r)},a=qs.stringify(o(u));i[n]("?".concat(a))},params:r,match:n,location:t,history:i}},[r,n,t,i,e])}var index=Object.freeze({usePrevious:usePrevious,usePromise:usePromise,usePromiseCallback:usePromiseCallback,useRouter:useRouter});exports.hooks=index; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),reactRouterDom=require("react-router-dom"),qs=_interopDefault(require("qs"));function usePrevious(e){var r=React.useRef();return React.useEffect(function(){r.current=e},[e]),r.current}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _objectSpread(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(e){_defineProperty(r,e,t[e])})}return r}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_nonIterableRest()}function _toArray(e){return _arrayWithHoles(e)||_iterableToArray(e)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var r=0,t=new Array(e.length);r<e.length;r++)t[r]=e[r];return t}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,r){var t=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(t.push(u.value),!r||t.length!==r);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return t}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var setLoading=function(e){return{result:e.result,loading:!0}};function usePromiseCallback(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,n=_slicedToArray(React.useState({}),2),o=n[0],a=n[1],u=React.useRef(0),i=React.useRef(0),c=React.useCallback(function(){t?(clearTimeout(u.current),u.current=setTimeout(function(){return a(setLoading)},t)):a(setLoading);var r=++i.current;return e.apply(void 0,arguments).then(function(e){return r===i.current&&a({result:e})}).catch(function(e){return r===i.current&&a({err:e})}).finally(function(){return r===i.current&&clearTimeout(u.current)})},r);return React.useEffect(function(){i.current=0,clearTimeout(u.current)},[]),[c,o.result,o.loading,o.err]}function usePromise(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],t=_toArray(usePromiseCallback(e,r,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0)),n=t[0],o=t.slice(1),a=React.useCallback(function(){return n.apply(void 0,_toConsumableArray(r))},[n]);return React.useEffect(function(){a.apply(void 0,_toConsumableArray(r))},[a]),[a].concat(_toConsumableArray(o))}function useStorage(t,r){function n(e,r){try{var t=o.getItem(e);return t?JSON.parse(t):r}catch(e){return console.log(e),r}}var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:window.localStorage,e=_slicedToArray(React.useState(function(){return n(t,r)}),2),a=e[0],u=e[1];React.useEffect(function(){var e=n(t,r);u(e)},[t]);return[a,function(e){try{var r=e instanceof Function?e(a):e;o.setItem(t,JSON.stringify(r)),u(r)}catch(e){console.log(e)}}]}var defaultOptions={ignoreQueryPrefix:!0,interpretNumericEntities:!0};function useRouter(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultOptions,r=reactRouterDom.useParams(),t=reactRouterDom.useLocation(),i=reactRouterDom.useHistory(),n=reactRouterDom.useRouteMatch();return React__default.useMemo(function(){var u=qs.parse(t.search,e);return{push:i.push,replace:i.replace,pathname:t.pathname,query:u,setQuery:function(r,e){var t=(1<arguments.length&&void 0!==e?e:{}).method,n=void 0===t?"push":t,o="function"==typeof r?r:function(e){return _objectSpread({},e,r)},a=qs.stringify(o(u));i[n]("?".concat(a))},params:r,match:n,location:t,history:i}},[r,n,t,i,e])}var index=Object.freeze({usePrevious:usePrevious,usePromise:usePromise,usePromiseCallback:usePromiseCallback,useStorage:useStorage,useRouter:useRouter});exports.hooks=index; |
@@ -98,4 +98,4 @@ { | ||
}, | ||
"version": "2.0.4", | ||
"gitHead": "628a3e50b93bdb329542ba881fbbec7c253a14fa" | ||
"version": "2.0.5", | ||
"gitHead": "7e5b873f0080674b4d2d1533ac16a851281a92cf" | ||
} |
@@ -7,2 +7,3 @@ /** | ||
export { usePromise, usePromiseCallback } from "./usePromise" | ||
export { useStorage } from "./useStorage" | ||
export { useRouter } from "./useRouter" |
@@ -6,6 +6,5 @@ /* eslint-disable max-lines */ | ||
import { act } from "react-dom/test-utils" | ||
import { usePromise, usePromiseCallback, usePrevious, useRouter } from "." | ||
import { usePromise, usePromiseCallback, usePrevious, useRouter, useStorage } from "." | ||
import { MemoryRouter } from "react-router-dom" | ||
import _ from "lodash" | ||
import useStorage from "./useStorage" | ||
@@ -12,0 +11,0 @@ describe("usePromise and usePromiseCallback hooks", () => { |
@@ -1,5 +0,5 @@ | ||
import React from "react" | ||
import { useState, useEffect } from "react" | ||
// https://usehooks.com/useLocalStorage/ | ||
function useStorage(key, initialValue, storage = window.localStorage) { | ||
export function useStorage(key, initialValue, storage = window.localStorage) { | ||
const getValue = (key, initialValue) => { | ||
@@ -19,5 +19,5 @@ try { | ||
// Pass initial state function to useState so logic is only executed once | ||
const [storedValue, setStoredValue] = React.useState(() => getValue(key, initialValue)) | ||
const [storedValue, setStoredValue] = useState(() => getValue(key, initialValue)) | ||
React.useEffect(() => { | ||
useEffect(() => { | ||
const val = getValue(key, initialValue) | ||
@@ -45,3 +45,1 @@ setStoredValue(val) | ||
} | ||
export default useStorage |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
266258
10