From 5d23490000511f52db5832ecb15b72628312f316 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 20:34:36 +0100 Subject: [PATCH 1/8] fix for useDisposable, update some dev deps --- package.json | 12 +- src/useDisposable.ts | 27 +-- yarn.lock | 451 ++++++++++++++++++++++++++----------------- 3 files changed, 292 insertions(+), 198 deletions(-) diff --git a/package.json b/package.json index e8f46065..0337e4f6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "coveralls": "^3.0.2", "husky": "^1.1.3", "jest": "^23.6.0", - "jest-dom": "^2.1.1", + "jest-dom": "^3.0.0", "jest-environment-jsdom": "^23.4.0", "jest-mock-console": "^0.4.0", "lint-staged": "^8.0.4", @@ -51,14 +51,14 @@ "react-dom": "16.8.0-alpha.0", "react-testing-library": "^5.2.3", "rimraf": "^2.6.2", - "rollup": "^0.67.0", + "rollup": "^1.1.0", "rollup-plugin-alias": "^1.4.0", "rollup-plugin-commonjs": "^9.2.0", - "rollup-plugin-filesize": "^5.0.1", - "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-filesize": "^6.0.0", + "rollup-plugin-node-resolve": "^4.0.0", "rollup-plugin-replace": "^2.1.0", - "rollup-plugin-terser": "^3.0.0", - "rollup-plugin-typescript2": "^0.17.2", + "rollup-plugin-terser": "^4.0.0", + "rollup-plugin-typescript2": "^0.19.0", "ts-jest": "^23.10.4", "tslint": "^5.11.0", "tslint-config-prettier": "^1.15.0", diff --git a/src/useDisposable.ts b/src/useDisposable.ts index 639a6d66..6317e2db 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef } from "react" +import { useEffect, useRef } from "react" type TDisposable = () => void @@ -16,20 +16,23 @@ export function useDisposable( disposerGenerator: () => D, inputs: ReadonlyArray = [] ): D { - const disposerRef = useRef(undefined) + const disposer = useRef(undefined) - useMemo(() => { - disposerRef.current = disposerGenerator() + useEffect(() => { + return lazyCreateDisposer() }, inputs) - useEffect( - () => () => { - if (disposerRef.current && typeof disposerRef.current === "function") { - disposerRef.current() + const lazyCreateDisposer = () => { + if (!disposer.current) { + disposer.current = disposerGenerator() + } + return () => { + if (typeof disposer.current === "function") { + disposer.current() } - }, - inputs - ) + disposer.current = undefined + } + } - return disposerRef.current! + return lazyCreateDisposer() as D } diff --git a/yarn.lock b/yarn.lock index 8386b01b..e33dab8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,6 +18,27 @@ esutils "^2.0.2" js-tokens "^4.0.0" +"@babel/runtime@^7.1.5": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.2.0.tgz#b03e42eeddf5898e00646e4c840fa07ba8dcad7f" + integrity sha512-oouEibCbHMVdZSDlJBO6bZmID/zA/G/Qx3H1d3rSNPTD+L8UNKvCat7aKWSJ74zYbm5zWGh0GQN0hKj8zYFTCg== + dependencies: + regenerator-runtime "^0.12.0" + +"@iamstarkov/listr-update-renderer@0.4.1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/@iamstarkov/listr-update-renderer/-/listr-update-renderer-0.4.1.tgz#d7c48092a2dcf90fd672b6c8b458649cb350c77e" + integrity sha512-IJyxQWsYDEkf8C8QthBn5N8tIUR9V9je6j3sMIpAkonaadjbvxmRC6RAhpa3RKxndhNnU2M6iNbtJwd7usQYIA== + dependencies: + chalk "^1.1.3" + cli-truncate "^0.2.1" + elegant-spinner "^1.0.1" + figures "^1.7.0" + indent-string "^3.0.0" + log-symbols "^1.0.2" + log-update "^2.3.0" + strip-ansi "^3.0.1" + "@samverschueren/stream-to-observable@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f" @@ -36,32 +57,31 @@ integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== "@types/jest@^23.3.9": - version "23.3.9" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.9.tgz#c16b55186ee73ae65e001fbee69d392c51337ad1" - integrity sha512-wNMwXSUcwyYajtbayfPp55tSayuDVU6PfY5gzvRSj80UvxdXEJOVPnUVajaOp7NgXLm+1e2ZDLULmpsU9vDvQw== + version "23.3.12" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.12.tgz#7e0ced251fa94c3bc2d1023d4b84b2992fa06376" + integrity sha512-/kQvbVzdEpOq4tEWT79yAHSM4nH4xMlhJv2GrLVQt4Qmo8yYsPdioBM1QpN/2GX1wkfMnyXvdoftvLUr0LBj7Q== "@types/node@*", "@types/node@^10.0.0": - version "10.12.9" - resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.9.tgz#a07bfa74331471e1dc22a47eb72026843f7b95c8" - integrity sha512-eajkMXG812/w3w4a1OcBlaTwsFPO5F7fJ/amy+tieQxEMWBlbV1JGSjkFM+zkHNf81Cad+dfIRA+IBkvmvdAeA== + version "10.12.18" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67" + integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== "@types/prop-types@*": - version "15.5.6" - resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.6.tgz#9c03d3fed70a8d517c191b7734da2879b50ca26c" - integrity sha512-ZBFR7TROLVzCkswA3Fmqq+IIJt62/T7aY/Dmz+QkU7CaW2QFqAitCE8Ups7IzmGhcN1YWMBT4Qcoc07jU9hOJQ== + version "15.5.8" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce" + integrity sha512-3AQoUxQcQtLHsK25wtTWIoIpgYjH3vSDroZOUr7PpCHw/jLY1RB9z9E8dBT/OSmwStVgkRNvdh+ZHNiomRieaw== "@types/react-dom@^16.0.9": - version "16.0.9" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.9.tgz#73ceb7abe6703822eab6600e65c5c52efd07fb91" - integrity sha512-4Z0bW+75zeQgsEg7RaNuS1k9MKhci7oQqZXxrV5KUGIyXZHHAAL3KA4rjhdH8o6foZ5xsRMSqkoM5A3yRVPR5w== + version "16.0.11" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.11.tgz#bd10ccb0d9260343f4b9a49d4f7a8330a5c1f081" + integrity sha512-x6zUx9/42B5Kl2Vl9HlopV8JF64wLpX3c+Pst9kc1HgzrsH+mkehe/zmHMQTplIrR48H2gpU7ZqurQolYu8XBA== dependencies: - "@types/node" "*" "@types/react" "*" "@types/react@*", "@types/react@^16.7.2": - version "16.7.6" - resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.6.tgz#80e4bab0d0731ad3ae51f320c4b08bdca5f03040" - integrity sha512-QBUfzftr/8eg/q3ZRgf/GaDP6rTYc7ZNem+g4oZM38C9vXyV8AWRWaTQuW5yCoZTsfHrN7b3DeEiUnqH9SrnpA== + version "16.7.20" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.20.tgz#13ae752c012710d0fa800985ca809814b51d3b58" + integrity sha512-Qd5RWkwl6SL7R2XzLk/cicjVQm1Mhc6HqXY5Ei4pWd1Vi8Fkbd5O0sA398x8fRSTPAuHdDYD9nrWmJMYTJI0vQ== dependencies: "@types/prop-types" "*" csstype "^2.2.0" @@ -99,6 +119,11 @@ acorn@^6.0.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.4.tgz#77377e7353b72ec5104550aa2d2097a2fd40b754" integrity sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg== +acorn@^6.0.5: + version "6.0.5" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.5.tgz#81730c0815f3f3b34d8efa95cb7430965f4d887a" + integrity sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg== + ajv@^6.5.5: version "6.5.5" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.5.tgz#cf97cdade71c6399a92c6d6c4177381291b781a1" @@ -593,10 +618,10 @@ builtin-modules@^1.0.0, builtin-modules@^1.1.1: resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8= -builtin-modules@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-2.0.0.tgz#60b7ef5ae6546bd7deefa74b08b62a43a232648e" - integrity sha512-3U5kUA5VPsRUA3nofm/BXX7GVHKfxz0hOBAPxXrIvHzlDRkQVqEn6yi8QJegxl4LzOHLdvb7XF5dVawa/VVYBg== +builtin-modules@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.0.0.tgz#1e587d44b006620d90286cc7a9238bbc6129cab1" + integrity sha512-hMIeU4K2ilbXV6Uv93ZZ0Avg/M91RaKXucQ+4me2Do1txxBDyDZWCBa5bJSLqoNTRpXTLwEzIk1KmloenDDjhg== cache-base@^1.0.1: version "1.0.1" @@ -665,7 +690,7 @@ chalk@^1.0.0, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1: +chalk@^2.0.0, chalk@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" integrity sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ== @@ -674,6 +699,15 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1: + version "2.4.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + chownr@^1.0.1, chownr@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494" @@ -684,6 +718,11 @@ ci-info@^1.5.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A== +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + class-utils@^0.3.5: version "0.3.6" resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -699,14 +738,7 @@ cli-boxes@^1.0.0: resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143" integrity sha1-T6kXw+WclKAEzWH47lCdplFocUM= -cli-cursor@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987" - integrity sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc= - dependencies: - restore-cursor "^1.0.1" - -cli-cursor@^2.0.0: +cli-cursor@^2.0.0, cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU= @@ -819,7 +851,16 @@ core-util-is@1.0.2, core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= -cosmiconfig@^5.0.2, cosmiconfig@^5.0.6: +cosmiconfig@5.0.6: + version "5.0.6" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.6.tgz#dca6cf680a0bd03589aff684700858c81abeeb39" + integrity sha512-6DWfizHriCrFWURP1/qyhsiFvYdlJzbCzmtFWh744+KyWsJo5+kPzUZZaMRSSItoYc0pxFX7gEO7ZC1/gN/7AQ== + dependencies: + is-directory "^0.3.1" + js-yaml "^3.9.0" + parse-json "^4.0.0" + +cosmiconfig@^5.0.7: version "5.0.7" resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.7.tgz#39826b292ee0d78eda137dfa3173bd1c21a43b04" integrity sha512-PcLqxTKiDmNT6pSpy4N6KtuPwb53W+2tzNvwOZw0WH9N6O0vLIBq0x8aj8Oj75ere4YcGi48bDFCL+3fRJdlNA== @@ -884,9 +925,9 @@ cssstyle@^1.0.0: cssom "0.3.x" csstype@^2.2.0: - version "2.5.7" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff" - integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw== + version "2.6.0" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.0.tgz#6cf7b2fa7fc32aab3d746802c244d4eda71371a2" + integrity sha512-by8hi8BlLbowQq0qtkx54d9aN73R9oUW20HISpka5kmgsR9F7nnxgfsemuR2sdCKZh+CDNf5egW9UZMm4mgJRg== dashdash@^1.12.0: version "1.14.1" @@ -905,9 +946,9 @@ data-urls@^1.0.0: whatwg-url "^7.0.0" date-fns@^1.27.2: - version "1.29.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.29.0.tgz#12e609cdcb935127311d04d33334e2960a2a54e6" - integrity sha512-lbTXWZ6M20cWH8N9S6afb0SBm6tMk+uUg6z3MqHPKE9atmsY3kJkTm8vKe93izJ2B2+q5MV990sM2CHgtAZaOw== + version "1.30.1" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c" + integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw== debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: version "2.6.9" @@ -924,9 +965,9 @@ debug@^3.1.0: ms "^2.1.1" debug@^4.0.1: - version "4.1.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.0.tgz#373687bffa678b38b1cd91f861b63850035ddc87" - integrity sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg== + version "4.1.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" + integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== dependencies: ms "^2.1.1" @@ -1049,14 +1090,15 @@ diff@^3.2.0: resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== -dom-testing-library@^3.12.0: - version "3.12.3" - resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-3.12.3.tgz#16c2fbd5198e175cb5499dabf9c64a893724015e" - integrity sha512-HvoxiKm8s4Gf+T52MX+gYHKXkGBM4ZiKYElIZxt8zPZtbT3wokrjKHskzryRqRD3oAKeg6chtUe3gchrurhmvA== +dom-testing-library@^3.13.1: + version "3.16.3" + resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-3.16.3.tgz#9dbf88d0a0c12f653248ad8f2a5aa17cc66f85e9" + integrity sha512-AZJJ/lmw+/yZxUVWoua5BofYK9EAQ/7Ai2wldUb6mSjE1XZy2H/+IrhG57lp3GqYN5WK7c2HzBLu8lW3c6/bXQ== dependencies: + "@babel/runtime" "^7.1.5" "@sheerun/mutationobserver-shim" "^0.3.2" pretty-format "^23.6.0" - wait-for-expect "^1.0.0" + wait-for-expect "^1.1.0" domexception@^1.0.1: version "1.0.1" @@ -1122,7 +1164,7 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^ resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -escodegen@^1.9.1: +escodegen@^1.11.0, escodegen@^1.9.1: version "1.11.0" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.11.0.tgz#b27a9389481d5bfd5bec76f7bb1eb3f8f4556589" integrity sha512-IeMV45ReixHS53K/OmfKAIztN/igDHzTJUhZM3k1jMhIZWjk45SMwAtBsEXiJp3vSPmTcu6CXn7mDvFHRN66fw== @@ -1192,11 +1234,6 @@ execa@^1.0.0: signal-exit "^3.0.0" strip-eof "^1.0.0" -exit-hook@^1.0.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8" - integrity sha1-8FyiM7SMBdVP/wd2XfhQfpXAL/g= - exit@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" @@ -1327,6 +1364,13 @@ figures@^1.7.0: escape-string-regexp "^1.0.5" object-assign "^4.1.0" +figures@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" + integrity sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI= + dependencies: + escape-string-regexp "^1.0.5" + filename-regex@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" @@ -1431,10 +1475,10 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== -fs-extra@7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.0.tgz#8cc3f47ce07ef7b3593a11b9fb245f7e34c041d6" - integrity sha512-EglNDLRpmaTWiD/qraZn6HREAEAHJcJOmxNEYwq6xeMKnVMAy3GUcFB+wXt2C6k4CNvB/mP1y/U3dzvKKj5OtQ== +fs-extra@7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" + integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== dependencies: graceful-fs "^4.1.2" jsonfile "^4.0.0" @@ -1547,7 +1591,7 @@ glob-parent@^2.0.0: dependencies: is-glob "^2.0.0" -glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: +glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3: version "7.1.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ== @@ -1717,15 +1761,15 @@ http-signature@~1.2.0: sshpk "^1.7.0" husky@^1.1.3: - version "1.1.4" - resolved "https://registry.yarnpkg.com/husky/-/husky-1.1.4.tgz#92f61383527d2571e9586234e5864356bfaceaa9" - integrity sha512-cZjGpS7qsaBSo3fOMUuR7erQloX3l5XzL1v/RkIqU6zrQImDdU70z5Re9fGDp7+kbYlM2EtS4aYMlahBeiCUGw== + version "1.3.1" + resolved "https://registry.yarnpkg.com/husky/-/husky-1.3.1.tgz#26823e399300388ca2afff11cfa8a86b0033fae0" + integrity sha512-86U6sVVVf4b5NYSZ0yvv88dRgBSSXXmHaiq5pP4KDj5JVzdwKgBjEtUPOm8hcoytezFwbU+7gotXNhpHdystlg== dependencies: - cosmiconfig "^5.0.6" + cosmiconfig "^5.0.7" execa "^1.0.0" find-up "^3.0.0" get-stdin "^6.0.0" - is-ci "^1.2.1" + is-ci "^2.0.0" pkg-dir "^3.0.0" please-upgrade-node "^3.1.1" read-pkg "^4.0.1" @@ -1848,13 +1892,20 @@ is-callable@^1.1.3, is-callable@^1.1.4: resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA== -is-ci@^1.0.10, is-ci@^1.2.1: +is-ci@^1.0.10: version "1.2.1" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.2.1.tgz#e3779c8ee17fccf428488f6e281187f2e632841c" integrity sha512-s6tfsaQaQi3JNciBH6shVqEDvhGut0SUXr31ag8Pd8BBbVVlcGfWhpPmEOoM6RJ5TFhbypvf5yyRw/VXW1IiWg== dependencies: ci-info "^1.5.0" +is-ci@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" + integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== + dependencies: + ci-info "^2.0.0" + is-data-descriptor@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" @@ -2268,10 +2319,10 @@ jest-docblock@^23.2.0: dependencies: detect-newline "^2.1.0" -jest-dom@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/jest-dom/-/jest-dom-2.1.1.tgz#c75515ef31147bd9684c860b0cba9605638fd4dd" - integrity sha512-jE1LRnP/wVGdQy6sVJ+dPwMq6rXXuvYTnzWEb8hDwfxhQesoaaukJzZaZYi14JPpdmhrncdpUsZpagN7HjuTsw== +jest-dom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/jest-dom/-/jest-dom-3.0.0.tgz#d669f6e335ed5eaf0773889bd221eb3d6bce78a9" + integrity sha512-Hdzihk5dI6RCPoGbMayd9SDEluoof9FrdyrCF8S3uKYScbxveu3+YltEveYn0hog666W4E0GX5D8zC3kV8U3MQ== dependencies: chalk "^2.4.1" css "^2.2.3" @@ -2371,9 +2422,9 @@ jest-message-util@^23.4.0: stack-utils "^1.0.1" jest-mock-console@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/jest-mock-console/-/jest-mock-console-0.4.0.tgz#813214cf39b858cb319983ef35ed02cb0618cdc4" - integrity sha512-WElCbNvfqQlD7cpfHfTn1ytZ+RjKg1Ftrvr5wEjdWP7a9esXmaiZuEAPeYUSK5fd0Cra+dR1oF8HAjjKKxDQdg== + version "0.4.2" + resolved "https://registry.yarnpkg.com/jest-mock-console/-/jest-mock-console-0.4.2.tgz#6caf471a66cdb88222ae09a4520af192176765f6" + integrity sha512-24ryiWYf/pmvOLlelLg4+K2umMI4IFcLls1hluJzs22jGVXzdqpfcMMSXaWdAzbTJ+C0qlSdvj06fqvqFyRO1A== jest-mock@^23.2.0: version "23.2.0" @@ -2509,6 +2560,14 @@ jest-worker@^23.2.0: dependencies: merge-stream "^1.0.1" +jest-worker@^24.0.0-alpha.9: + version "24.0.0-alpha.12" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-24.0.0-alpha.12.tgz#b7ca1fb774b4eddc342768b7a63d89be5e6a762f" + integrity sha512-BzGiUwc2LPyrvOuCMqdiLqWU78C+lHbHI/hcJgWonTda0RS7aCcrgSJx5t9+56U9rzMMxDC75S9khJ0oi3fYQA== + dependencies: + merge-stream "^1.0.1" + supports-color "^5.5.0" + jest@^23.6.0: version "23.6.0" resolved "https://registry.yarnpkg.com/jest/-/jest-23.6.0.tgz#ad5835e923ebf6e19e7a1d7529a432edfee7813d" @@ -2527,7 +2586,7 @@ js-tokens@^3.0.2: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= -js-yaml@^3.11.0, js-yaml@^3.7.0, js-yaml@^3.9.0: +js-yaml@^3.11.0: version "3.12.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" integrity sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A== @@ -2535,6 +2594,14 @@ js-yaml@^3.11.0, js-yaml@^3.7.0, js-yaml@^3.9.0: argparse "^1.0.7" esprima "^4.0.0" +js-yaml@^3.7.0, js-yaml@^3.9.0: + version "3.12.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.1.tgz#295c8632a18a23e054cf5c9d3cecafe678167600" + integrity sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" @@ -2655,6 +2722,11 @@ kleur@^2.0.1: resolved "https://registry.yarnpkg.com/kleur/-/kleur-2.0.2.tgz#b704f4944d95e255d038f0cb05fb8a602c55a300" integrity sha512-77XF9iTllATmG9lSlIv0qdQ2BQ/h9t0bJllHlbvsQ0zUWfU7Yi0S8L5JXzPZgkefIiajLmBJJ4BsMJmqcf7oxQ== +lave@^1.1.10: + version "1.1.10" + resolved "https://registry.yarnpkg.com/lave/-/lave-1.1.10.tgz#062207652c5502d7c6ff096c9de3995401f634d5" + integrity sha1-BiIHZSxVAtfG/wlsneOZVAH2NNU= + lcid@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835" @@ -2686,13 +2758,14 @@ levn@~0.3.0: type-check "~0.3.2" lint-staged@^8.0.4: - version "8.0.4" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.0.4.tgz#d3c909fcf7897152cdce2d6e42500cd9b5b41a0d" - integrity sha512-Rs0VxXoyFqHMrPQgKAMy+O907+m5Po71UVPhBi7BUBwU7ZZ2aoc+mZmpOX3DVPCoTcy6+hqJa9yIZfacNpJHdg== + version "8.1.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.1.0.tgz#dbc3ae2565366d8f20efb9f9799d076da64863f2" + integrity sha512-yfSkyJy7EuVsaoxtUSEhrD81spdJOe/gMTGea3XaV7HyoRhTb9Gdlp6/JppRZERvKSEYXP9bjcmq6CA5oL2lYQ== dependencies: + "@iamstarkov/listr-update-renderer" "0.4.1" chalk "^2.3.1" commander "^2.14.1" - cosmiconfig "^5.0.2" + cosmiconfig "5.0.6" debug "^3.1.0" dedent "^0.7.0" del "^3.0.0" @@ -2703,7 +2776,6 @@ lint-staged@^8.0.4: is-windows "^1.0.2" jest-validate "^23.5.0" listr "^0.14.2" - listr-update-renderer "https://github.com/okonet/listr-update-renderer/tarball/upgrade-log-update" lodash "^4.17.5" log-symbols "^2.2.0" micromatch "^3.1.8" @@ -2721,9 +2793,10 @@ listr-silent-renderer@^1.1.1: resolved "https://registry.yarnpkg.com/listr-silent-renderer/-/listr-silent-renderer-1.1.1.tgz#924b5a3757153770bf1a8e3fbf74b8bbf3f9242e" integrity sha1-kktaN1cVN3C/Go4/v3S4u/P5JC4= -listr-update-renderer@^0.4.0, "listr-update-renderer@https://github.com/okonet/listr-update-renderer/tarball/upgrade-log-update": - version "0.4.0" - resolved "https://github.com/okonet/listr-update-renderer/tarball/upgrade-log-update#06073fa93166277607a7814f4e1f83960081414c" +listr-update-renderer@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/listr-update-renderer/-/listr-update-renderer-0.5.0.tgz#4ea8368548a7b8aecb7e06d8c95cb45ae2ede6a2" + integrity sha512-tKRsZpKz8GSGqoI/+caPmfrypiaq+OQCbd+CovEC24uk1h952lVj5sC7SqyFUm+OaJ5HN/a1YLt5cit2FMNsFA== dependencies: chalk "^1.1.3" cli-truncate "^0.2.1" @@ -2734,30 +2807,30 @@ listr-update-renderer@^0.4.0, "listr-update-renderer@https://github.com/okonet/l log-update "^2.3.0" strip-ansi "^3.0.1" -listr-verbose-renderer@^0.4.0: - version "0.4.1" - resolved "https://registry.yarnpkg.com/listr-verbose-renderer/-/listr-verbose-renderer-0.4.1.tgz#8206f4cf6d52ddc5827e5fd14989e0e965933a35" - integrity sha1-ggb0z21S3cWCfl/RSYng6WWTOjU= +listr-verbose-renderer@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/listr-verbose-renderer/-/listr-verbose-renderer-0.5.0.tgz#f1132167535ea4c1261102b9f28dac7cba1e03db" + integrity sha512-04PDPqSlsqIOaaaGZ+41vq5FejI9auqTInicFRndCBgE3bXG8D6W1I+mWhk+1nqbHmyhla/6BUrd5OSiHwKRXw== dependencies: - chalk "^1.1.3" - cli-cursor "^1.0.2" + chalk "^2.4.1" + cli-cursor "^2.1.0" date-fns "^1.27.2" - figures "^1.7.0" + figures "^2.0.0" listr@^0.14.2: - version "0.14.2" - resolved "https://registry.yarnpkg.com/listr/-/listr-0.14.2.tgz#cbe44b021100a15376addfc2d79349ee430bfe14" - integrity sha512-vmaNJ1KlGuGWShHI35X/F8r9xxS0VTHh9GejVXwSN20fG5xpq3Jh4bJbnumoT6q5EDM/8/YP1z3YMtQbFmhuXw== + version "0.14.3" + resolved "https://registry.yarnpkg.com/listr/-/listr-0.14.3.tgz#2fea909604e434be464c50bddba0d496928fa586" + integrity sha512-RmAl7su35BFd/xoMamRjpIE4j3v+L28o8CT5YhAXQJm1fD+1l9ngXY8JAQRJ+tFK2i5njvi0iRUKV09vPwA0iA== dependencies: "@samverschueren/stream-to-observable" "^0.3.0" is-observable "^1.1.0" is-promise "^2.1.0" is-stream "^1.1.0" listr-silent-renderer "^1.1.1" - listr-update-renderer "^0.4.0" - listr-verbose-renderer "^0.4.0" - p-map "^1.1.1" - rxjs "^6.1.0" + listr-update-renderer "^0.5.0" + listr-verbose-renderer "^0.5.0" + p-map "^2.0.0" + rxjs "^6.3.3" load-json-file@^1.0.0: version "1.1.0" @@ -3014,9 +3087,9 @@ mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1: minimist "0.0.8" mobx@^5.0.0: - version "5.6.0" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.6.0.tgz#e381c357e0ed7685a99a896455ecc66ff5ab84ee" - integrity sha512-xrA0tBnSMANXCDjS2W/6YTasesA8mkg9o+v/Bw/OcbXaRVE6/soVwDMWIh7A6TwMDY4tYQprQJZ5WQN1TRSb3A== + version "5.8.0" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.8.0.tgz#cf59eae4baa2fde4387ffb6462b7ccf3b497b03c" + integrity sha512-NsZB+9bF5j+nv9Qwk6bNeE3np26a4TbTGkMpOLf6o1zXoM9BtHPQn/00px4uZ2AXJXtQML5P4MEWdMm6icMIfQ== ms@2.0.0: version "2.0.0" @@ -3259,11 +3332,6 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: dependencies: wrappy "1" -onetime@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789" - integrity sha1-ofeDj4MUxRbwXs78vEzP4EtO14k= - onetime@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" @@ -3331,9 +3399,9 @@ p-limit@^1.1.0: p-try "^1.0.0" p-limit@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.0.0.tgz#e624ed54ee8c460a778b3c9f3670496ff8a57aec" - integrity sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A== + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.1.0.tgz#1d5a0d20fb12707c758a655f6bbc4386b5930d68" + integrity sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g== dependencies: p-try "^2.0.0" @@ -3356,6 +3424,11 @@ p-map@^1.1.1: resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" integrity sha512-r6zKACMNhjPJMTl8KcFH4li//gkrXWfbD6feV8l6doRHlzljFWGJ2AP6iKaCJXyZmAUMOPtvbW7EXkbWO/pLEA== +p-map@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.0.0.tgz#be18c5a5adeb8e156460651421aceca56c213a50" + integrity sha512-GO107XdrSUmtHxVoi60qc9tUl/KkNKm+X2CF4P9amalpGxv5YqVPJNfSb0wcA+syCopkZvYYIzW8OVTQW59x/w== + p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" @@ -3428,7 +3501,7 @@ path-key@^2.0.0, path-key@^2.0.1: resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= -path-parse@^1.0.5: +path-parse@^1.0.5, path-parse@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== @@ -3533,9 +3606,9 @@ preserve@^0.2.0: integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= prettier@^1.15.2: - version "1.15.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.2.tgz#d31abe22afa4351efa14c7f8b94b58bb7452205e" - integrity sha512-YgPLFFA0CdKL4Eg2IHtUSjzj/BWgszDHiNQAe0VAIBse34148whfdzLagRL+QiKS+YfK5ftB6X4v/MBw8yCoug== + version "1.15.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.3.tgz#1feaac5bdd181237b54dbe65d874e02a1472786a" + integrity sha512-gAU9AGAPMaKb3NNSUUuhhFAS7SCO4ALTN4nRIn6PJ075Qd28Yn2Ig2ahEJWdJwJmlEBTUfC7mMUSFy8MwsOCfg== pretty-format@^23.6.0: version "23.6.0" @@ -3639,7 +3712,7 @@ rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-dom@^16.8.0-alpha.0: +react-dom@16.8.0-alpha.0: version "16.8.0-alpha.0" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.0-alpha.0.tgz#47bbcf42593eab5468b577d3c3f3c27f251a65ef" integrity sha512-OGfLUXGxtMgqLB1BqnB9flVCvc8VvAnhQYeFr+EUzwiODcD34dPrxtfa7ccK4dwzcPi8HRLSyBcaQi2OvVoUww== @@ -3650,13 +3723,13 @@ react-dom@^16.8.0-alpha.0: scheduler "^0.13.0-alpha.0" react-testing-library@^5.2.3: - version "5.2.3" - resolved "https://registry.yarnpkg.com/react-testing-library/-/react-testing-library-5.2.3.tgz#c3be44bfa5eb1ba2acc1fb218785c40ebbdfe8ed" - integrity sha512-Bw52++7uORuIQnL55lK/WQfppqAc9+8yFG4lWUp/kmSOvYDnt8J9oI5fNCfAGSQi9iIhAv9aNsI2G5rtid0nrA== + version "5.4.4" + resolved "https://registry.yarnpkg.com/react-testing-library/-/react-testing-library-5.4.4.tgz#3fa787999492be94b228e4540a7211556bf4fd94" + integrity sha512-/TiERZ+URSNhZQfjrUXh0VLsiLSmhqP1WP+2e2wWqWqrRIWpcAxrfuBxzlT75LYMDNmicEikaXJqRDi/pqCEDg== dependencies: - dom-testing-library "^3.12.0" + dom-testing-library "^3.13.1" -react@^16.8.0-alpha.0: +react@16.8.0-alpha.0: version "16.8.0-alpha.0" resolved "https://registry.yarnpkg.com/react/-/react-16.8.0-alpha.0.tgz#8545eb79534cce5ba99ed40085f7f955e8857a19" integrity sha512-B/nJJkNqV4JAJQ1M0Q38ZvhZ6BoYsjyZq29hbsIIPYayn/0DcYhu7tExpfzdtTC0SnUcA+RnDBTlXTEJ5b9PEg== @@ -3725,6 +3798,11 @@ regenerator-runtime@^0.11.0: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== +regenerator-runtime@^0.12.0: + version "0.12.1" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de" + integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg== + regex-cache@^0.4.2: version "0.4.4" resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" @@ -3836,20 +3914,19 @@ resolve@1.1.7: resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= -resolve@1.8.1, resolve@^1.1.6, resolve@^1.3.2, resolve@^1.8.1: +resolve@1.8.1, resolve@^1.8.1: version "1.8.1" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26" integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA== dependencies: path-parse "^1.0.5" -restore-cursor@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" - integrity sha1-NGYfRohjJ/7SmRR5FSJS35LapUE= +resolve@1.x, resolve@^1.3.2: + version "1.9.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06" + integrity sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ== dependencies: - exit-hook "^1.0.0" - onetime "^1.0.0" + path-parse "^1.0.6" restore-cursor@^2.0.0: version "2.0.0" @@ -3864,7 +3941,14 @@ ret@~0.1.10: resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== -rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: +rimraf@^2.2.8, rimraf@^2.6.2: + version "2.6.3" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" + integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== + dependencies: + glob "^7.1.3" + +rimraf@^2.5.4, rimraf@^2.6.1: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" integrity sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w== @@ -3872,11 +3956,11 @@ rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: glob "^7.0.5" rollup-plugin-alias@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-1.4.0.tgz#120cba7c46621c03138f0ca6fd5dd2ade9872db9" - integrity sha512-lB094zdi19FS+1bVarVp9kBN0Zk41PdTGoCk0z8xesKO7RGjOo18cp1hUzEqrOQ4bM9+KLD9nbnu/XUxQm9pbg== + version "1.5.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-1.5.1.tgz#80cce3a967befda5b09c86abc14a043a78035b46" + integrity sha512-pQTYBRNfLedoVOO7AYHNegIavEIp4jKTga5jUi1r//KYgHKGWgG4qJXYhbcWKt2k1FwGlR5wCYoY+IFkme0t4A== dependencies: - slash "^1.0.0" + slash "^2.0.0" rollup-plugin-commonjs@^9.2.0: version "9.2.0" @@ -3888,10 +3972,10 @@ rollup-plugin-commonjs@^9.2.0: resolve "^1.8.1" rollup-pluginutils "^2.3.3" -rollup-plugin-filesize@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/rollup-plugin-filesize/-/rollup-plugin-filesize-5.0.1.tgz#442a994465abf4f4f63ea20ac3267c3e0d05ee5d" - integrity sha512-zVUkEuJ543D86EaC5Ql2M6d6aAXwWbRwJ9NWSzTUS7F3vdd1cf+zlL+roQY8sW2hLIpbDMnGfev0dcy4bHQbjw== +rollup-plugin-filesize@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-filesize/-/rollup-plugin-filesize-6.0.0.tgz#6188769eff2ee6f4508e0f6de5cf64409e2a269d" + integrity sha512-yU1nNkB2RP1PwLpBFIzH9oIwLL+Si6AEuy0/hAhFW+68hy6x/W/MxhhsUe7bDhG7Gnei7FOGC4Ag4W9+CninMQ== dependencies: boxen "^2.0.0" brotli-size "0.0.3" @@ -3901,14 +3985,14 @@ rollup-plugin-filesize@^5.0.1: gzip-size "^5.0.0" terser "^3.10.0" -rollup-plugin-node-resolve@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.4.0.tgz#908585eda12e393caac7498715a01e08606abc89" - integrity sha512-PJcd85dxfSBWih84ozRtBkB731OjXk0KnzN0oGp7WOWcarAFkVa71cV5hTJg2qpVsV2U8EUwrzHP3tvy9vS3qg== +rollup-plugin-node-resolve@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.0.0.tgz#9bc6b8205e9936cc0e26bba2415f1ecf1e64d9b2" + integrity sha512-7Ni+/M5RPSUBfUaP9alwYQiIKnKeXCOHiqBpKUl9kwp3jX5ZJtgXAait1cne6pGEVUUztPD6skIKH9Kq9sNtfw== dependencies: - builtin-modules "^2.0.0" + builtin-modules "^3.0.0" is-module "^1.0.0" - resolve "^1.1.6" + resolve "^1.8.1" rollup-plugin-replace@^2.1.0: version "2.1.0" @@ -3919,22 +4003,23 @@ rollup-plugin-replace@^2.1.0: minimatch "^3.0.2" rollup-pluginutils "^2.0.1" -rollup-plugin-terser@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-3.0.0.tgz#045bd7cf625ee1affcfe6971dab6fffe6fb48c65" - integrity sha512-Ed9zRD7OoCBnh0XGlEAJle5TCUsFXMLClwKzZWnS1zbNO4MelHjfCSdFZxCAdH70M40nhZ1nRrY2GZQJhSMcjA== +rollup-plugin-terser@^4.0.0: + version "4.0.2" + resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-4.0.2.tgz#78936d182ae7c4ecb313403ff5d5faad1b69e2aa" + integrity sha512-M2vY7NPMa3N77/avJSJyBva4nyBTiUM0kgMoWwEAeo2Edl3MW/GoM0069FzVrfMYP3xDqcVrDbaIOqVaBD8lHQ== dependencies: "@babel/code-frame" "^7.0.0" - jest-worker "^23.2.0" - serialize-javascript "^1.5.0" - terser "^3.8.2" + escodegen "^1.11.0" + jest-worker "^24.0.0-alpha.9" + lave "^1.1.10" + terser "^3.14.1" -rollup-plugin-typescript2@^0.17.2: - version "0.17.2" - resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.17.2.tgz#7d18a94b74993307ec69b7c2f571c12b51561a14" - integrity sha512-QmrZElI+p4sytmv1S7uvtUbL4XADWWmM/dIuc3agGZTE+fO2X1KoRo8EbeR1x0ZO4I9KwPubGfmw/1rHeUR+Dg== +rollup-plugin-typescript2@^0.19.0: + version "0.19.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.19.0.tgz#4b360f96d6932b0cf13f8e25fe1351387c530122" + integrity sha512-1U6UUfk1c0RwUhTvxDaEpNiAe3Wmz2es4hVXDN3FDJ1VVN2an9QG7sPL2/ZoLrFkLvZ1SJBi0rRtkmVmZrNFZA== dependencies: - fs-extra "7.0.0" + fs-extra "7.0.1" resolve "1.8.1" rollup-pluginutils "2.3.3" tslib "1.9.3" @@ -3947,13 +4032,14 @@ rollup-pluginutils@2.3.3, rollup-pluginutils@^2.0.1, rollup-pluginutils@^2.3.3: estree-walker "^0.5.2" micromatch "^2.3.11" -rollup@^0.67.0: - version "0.67.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.67.1.tgz#4094110c944d3c9e25b5bf196771b51132ec3adb" - integrity sha512-BfwL9pw5VyxrAWx/G1tP8epgG+NH4KcR78aoWacV7+dFp1Mj6ynH8QTIC/lDQ3KlwzDakqZmJQ4LQ7TmLg+pBA== +rollup@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.1.0.tgz#461a7534b55be48aa4a6e6810a1543a5769e75d1" + integrity sha512-NK03gkkOz0CchHBMGomcNqa6U3jLNzHuWK9SI0+1FV475JA6cQxVtjlDcQoKKDNIQ3IwYumIlgoKYDEWUyFBwQ== dependencies: "@types/estree" "0.0.39" "@types/node" "*" + acorn "^6.0.5" rsvp@^3.3.3: version "3.6.2" @@ -3965,7 +4051,7 @@ run-node@^1.0.0: resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e" integrity sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A== -rxjs@^6.1.0: +rxjs@^6.3.3: version "6.3.3" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz#3c6a7fa420e844a81390fb1158a9ec614f4bad55" integrity sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw== @@ -4011,9 +4097,9 @@ sax@^1.2.4: integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== scheduler@^0.13.0-alpha.0: - version "0.13.0-alpha.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.0-alpha.0.tgz#8fc1f01617b59e4543376735b2f954867d49110c" - integrity sha512-+DbRwO53hlLso4gzrSIqcfNe8eRMMaV4gd4eySGisbyLBrp5unTpAMR0UAbrqlQLTGhnOFNoQAfaZTz4iPj1RQ== + version "0.13.0-alpha.1" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.0-alpha.1.tgz#753977fb4fb35d8cdd559868a11e46b640955556" + integrity sha512-W0sH0848sVuPKg+I18vTYQyzVtA4X1lrVgSeXK6KnOPUltFdJcY5nkbTkjGUeS/E0x+eBsNYfSdhJtGjT95njw== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" @@ -4028,11 +4114,6 @@ semver-compare@^1.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004" integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg== -serialize-javascript@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe" - integrity sha512-Ga8c8NjAAp46Br4+0oZ2WxJCwIzwP60Gq1YPgU+39PiTVxyed/iKE/zyZI6+UlVYH5Q4PaQdHhcegIFPZTUfoQ== - set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -4198,9 +4279,9 @@ sourcemap-codec@^1.4.1: integrity sha512-vFrY/x/NdsD7Yc8mpTJXuao9S8lq08Z/kOITHz6b7YbfI9xL8Spe5EvSQUHOI7SbpY8bRPr0U3kKSsPuqEGSfA== spdx-correct@^3.0.0: - version "3.0.2" - resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.2.tgz#19bb409e91b47b1ad54159243f7312a858db3c2e" - integrity sha512-q9hedtzyXHr5S0A1vEPoK/7l8NpfkFYTq6iCY+Pno2ZbdZR6WexZFtqeVGkGxW3TEJMN914Z55EnAGMmenlIQQ== + version "3.1.0" + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.0.tgz#fb83e504445268f154b074e218c87c003cd31df4" + integrity sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q== dependencies: spdx-expression-parse "^3.0.0" spdx-license-ids "^3.0.0" @@ -4219,9 +4300,9 @@ spdx-expression-parse@^3.0.0: spdx-license-ids "^3.0.0" spdx-license-ids@^3.0.0: - version "3.0.2" - resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.2.tgz#a59efc09784c2a5bada13cfeaf5c75dd214044d2" - integrity sha512-qky9CVt0lVIECkEsYbNILVnPvycuEBkXoMFLRWsREkomQLevYhtRKC+R91a5TOAQ3bCMjikRwhyaRqj1VYatYg== + version "3.0.3" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz#81c0ce8f21474756148bbb5f3bfc0f36bf15d76e" + integrity sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g== split-string@^3.0.1, split-string@^3.0.2: version "3.1.0" @@ -4372,7 +4453,7 @@ supports-color@^3.1.2: dependencies: has-flag "^1.0.0" -supports-color@^5.3.0: +supports-color@^5.3.0, supports-color@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== @@ -4432,7 +4513,7 @@ term-size@^1.2.0: dependencies: execa "^0.7.0" -terser@^3.10.0, terser@^3.8.2: +terser@^3.10.0: version "3.10.11" resolved "https://registry.yarnpkg.com/terser/-/terser-3.10.11.tgz#e063da74b194dde9faf0a561f3a438c549d2da3f" integrity sha512-iruZ7j14oBbRYJC5cP0/vTU7YOWjN+J1ZskEGoF78tFzXdkK2hbCL/3TRZN8XB+MuvFhvOHMp7WkOCBO4VEL5g== @@ -4441,6 +4522,15 @@ terser@^3.10.0, terser@^3.8.2: source-map "~0.6.1" source-map-support "~0.5.6" +terser@^3.14.1: + version "3.14.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-3.14.1.tgz#cc4764014af570bc79c79742358bd46926018a32" + integrity sha512-NSo3E99QDbYSMeJaEk9YW2lTg3qS9V0aKGlb+PlOrei1X02r1wSBHCNX/O+yeTRFSWPKPIGj6MqvvdqV4rnVGw== + dependencies: + commander "~2.17.1" + source-map "~0.6.1" + source-map-support "~0.5.6" + test-exclude@^4.2.1: version "4.2.3" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.3.tgz#a9a5e64474e4398339245a0a769ad7c2f4a97c20" @@ -4518,9 +4608,9 @@ trim-right@^1.0.1: integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= ts-jest@^23.10.4: - version "23.10.4" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-23.10.4.tgz#a7a953f55c9165bcaa90ff91014a178e87fe0df8" - integrity sha512-oV/wBwGUS7olSk/9yWMiSIJWbz5xO4zhftnY3gwv6s4SMg6WHF1m8XZNBvQOKQRiTAexZ9754Z13dxBq3Zgssw== + version "23.10.5" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-23.10.5.tgz#cdb550df4466a30489bf70ba867615799f388dd5" + integrity sha512-MRCs9qnGoyKgFc8adDEntAOP64fWK1vZKnOYU1o2HxaqjdJvGqmkLCPCnVq1/If4zkUmEjKPnCiUisTrlX2p2A== dependencies: bs-logger "0.x" buffer-from "1.x" @@ -4528,6 +4618,7 @@ ts-jest@^23.10.4: json5 "2.x" make-error "1.x" mkdirp "0.x" + resolve "1.x" semver "^5.5" yargs-parser "10.x" @@ -4537,14 +4628,14 @@ tslib@1.9.3, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== tslint-config-prettier@^1.15.0: - version "1.16.0" - resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.16.0.tgz#4627d0e2639554d89210e480093c381b5186963f" - integrity sha512-zu6RAcpBtqdvhT6KpBh9kRPYATjOf9BnRi718kNqVKFjEgSE4rFrPprFju1YJrkOa3RbtbWI1ZSuLd2NBX1MDw== + version "1.17.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.17.0.tgz#946ed6117f98f3659a65848279156d87628c33dc" + integrity sha512-NKWNkThwqE4Snn4Cm6SZB7lV5RMDDFsBwz6fWUkTxOKGjMx8ycOHnjIbhn7dZd5XmssW3CwqUjlANR6EhP9YQw== tslint@^5.11.0: - version "5.11.0" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed" - integrity sha1-mPMMAurjzecAYgHkwzywi0hYHu0= + version "5.12.1" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.12.1.tgz#8cec9d454cf8a1de9b0a26d7bdbad6de362e52c1" + integrity sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw== dependencies: babel-code-frame "^6.22.0" builtin-modules "^1.1.1" @@ -4586,9 +4677,9 @@ type-check@~0.3.2: prelude-ls "~1.1.2" typescript@^3.1.6: - version "3.1.6" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68" - integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA== + version "3.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" + integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== uglify-js@^3.1.4: version "3.4.9" @@ -4680,7 +4771,7 @@ w3c-hr-time@^1.0.1: dependencies: browser-process-hrtime "^0.1.2" -wait-for-expect@^1.0.0: +wait-for-expect@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/wait-for-expect/-/wait-for-expect-1.1.0.tgz#6607375c3f79d32add35cd2c87ce13f351a3d453" integrity sha512-vQDokqxyMyknfX3luCDn16bSaRcOyH6gGuUXMIbxBLeTo6nWuEWYqMTT9a+44FmW8c2m6TRWBdNvBBjA1hwEKg== From 2a6e3af2bc274d34a740d9d8a49b299cfddd67b7 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 20:44:29 +0100 Subject: [PATCH 2/8] fix for early disposal when inputs change --- src/useDisposable.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/useDisposable.ts b/src/useDisposable.ts index 6317e2db..7e27c109 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -2,6 +2,10 @@ import { useEffect, useRef } from "react" type TDisposable = () => void +const doNothingDisposer = () => { + // empty +} + /** * Adds an observable effect (reaction, autorun, or anything else that returns a disposer) that will be registered upon component creation and disposed upon unmounting. * Returns the generated disposer for early disposal. @@ -17,12 +21,18 @@ export function useDisposable( inputs: ReadonlyArray = [] ): D { const disposer = useRef(undefined) + const earlyDisposed = useRef(false) useEffect(() => { - return lazyCreateDisposer() + return lazyCreateDisposer(false) }, inputs) - const lazyCreateDisposer = () => { + const lazyCreateDisposer = (earlyDisposal: boolean) => { + // ensure that we won't create a new disposer if it was early disposed + if (earlyDisposed.current) { + return doNothingDisposer + } + if (!disposer.current) { disposer.current = disposerGenerator() } @@ -31,8 +41,11 @@ export function useDisposable( disposer.current() } disposer.current = undefined + if (earlyDisposal) { + earlyDisposed.current = true + } } } - return lazyCreateDisposer() as D + return lazyCreateDisposer(true) as D } From cd93f0d9748a135dd4ae8dd3489cfb318a10485e Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 21:06:27 +0100 Subject: [PATCH 3/8] unit tests and little fix --- README.md | 18 +++---- src/useDisposable.ts | 5 +- src/utils.ts | 4 +- test/useDisposable.test.tsx | 103 +++++++++++++++++++++++++----------- 4 files changed, 85 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index cff2bdfa..f50a4bb7 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This is a next iteration of [mobx-react](https://github.com/mobxjs/mobx-react) coming from introducing React hooks which simplifies a lot of internal workings of this package. Class based components **are not supported** except using `` directly in its `render` method. **You need React version 16.7.0-alpha.2 or 16.8.0-alpha.0 which is highly experimental and not recommended for production.** + **Do not use React 16.7 as it's [missing Hooks support](https://reactjs.org/blog/2018/12/19/react-v-16-7.html)!** [![NPM](https://nodei.co/npm/mobx-react-lite.png)](https://www.npmjs.com/package/mobx-react-lite) @@ -19,7 +20,7 @@ Project is written in TypeScript and provides type safety out of the box. No Flo - [`useObserver(fn: () => T, baseComponentName = "observed"): T`](#useobservertfn---t-basecomponentname--%22observed%22-t) - [`useObservable(initialValue: T): T`](#useobservabletinitialvalue-t-t) - [`useComputed(func: () => T, inputs: ReadonlyArray = []): T`](#usecomputedfunc---t-inputs-readonlyarrayany---t) - - [`useDisposable(disposerGenerator: () => D, inputs: ReadonlyArray = []): D`](#usedisposabled-extends-ireactiondisposerdisposergenerator---d-inputs-readonlyarrayany---d) + - [`useDisposable(disposerGenerator: () => D, inputs: ReadonlyArray = []): D`](#usedisposabled-extends-ireactiondisposerdisposergenerator---d-inputs-readonlyarrayany---d) - [Server Side Rendering with `useStaticRendering`](#server-side-rendering-with-usestaticrendering) - [Why no Provider/inject?](#why-no-providerinject) - [What about smart/dumb components?](#what-about-smartdumb-components) @@ -203,7 +204,7 @@ Notice that since the computation depends on non-observable value, it has to be [![Edit Calculator](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jzj48v2xry?module=%2Fsrc%2FCalculator.tsx) -### `useDisposable(disposerGenerator: () => D, inputs: ReadonlyArray = []): D` +### `useDisposable(disposerGenerator: () => D, inputs: ReadonlyArray = []): D` The disposable is any kind of function that returns another function to be called on a component unmount to clean up used resources. Use MobX related functions like [`reaction`](https://mobx.js.org/refguide/reaction.html), [`autorun`](https://mobx.js.org/refguide/autorun.html), [`when`](https://mobx.js.org/refguide/when.html), [`observe`](https://mobx.js.org/refguide/observe.html), or anything else that returns a disposer. Returns the generated disposer for early disposal. @@ -277,7 +278,7 @@ function App({ children }) { The React hooks don't force anyone to suddenly have a state inside a _dumb component_ that is supposed to only render stuff. You can separate your concerns in a similar fashion. ```tsx -import { createSelector } from 'react-selector-hooks' +import { createSelector } from "react-selector-hooks" const userSelector = createSelector(({ user }) => ({ name: user.name, @@ -297,9 +298,9 @@ export default () => { // you may extract these two lines into a custom hook const store = useContext(StoreContext) const data = userSelector(store) - return UiComponent({...data}) + return UiComponent({ ...data }) // perhaps wrap it inside observer in here? - return observer(UiComponent({...data})) + return observer(UiComponent({ ...data })) } ``` @@ -308,14 +309,13 @@ It may look a bit more verbose than a _classic_ inject, but there is nothing sto ```tsx // make universal HOC -const inject = (useSelector, baseComponent) => ( - React.useMemo((props) => { +const inject = (useSelector, baseComponent) => + React.useMemo(props => { const store = useContext(StoreContext) const selected = useSelector(store) - + return baseComponent({ ...selected, ...props }) }) -) // use the HOC with a selector diff --git a/src/useDisposable.ts b/src/useDisposable.ts index 7e27c109..ef625f63 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -1,4 +1,4 @@ -import { useEffect, useRef } from "react" +import { useLayoutEffect, useRef } from "react" type TDisposable = () => void @@ -23,7 +23,8 @@ export function useDisposable( const disposer = useRef(undefined) const earlyDisposed = useRef(false) - useEffect(() => { + // we need to use layout effect since disposals need to be run synchronously + useLayoutEffect(() => { return lazyCreateDisposer(false) }, inputs) diff --git a/src/utils.ts b/src/utils.ts index 7480a1ef..52e3a019 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ -import { useEffect } from "react" +import { useLayoutEffect } from "react" const EMPTY_ARRAY: any[] = [] export function useUnmount(fn: () => void) { - useEffect(() => fn, EMPTY_ARRAY) + useLayoutEffect(() => fn, EMPTY_ARRAY) } diff --git a/test/useDisposable.test.tsx b/test/useDisposable.test.tsx index 71acdd7a..dc780bca 100644 --- a/test/useDisposable.test.tsx +++ b/test/useDisposable.test.tsx @@ -7,78 +7,117 @@ import { observer, useDisposable } from "../src" afterEach(cleanup) test("reactions run and dispose properly", async () => { + let reactions1Created = 0 + let reactions2Created = 0 let reactions1 = 0 let reactions2 = 0 let renders = 0 - let reactionDisposerCalls = 0 + let reaction1DisposerCalls = 0 + let reaction2DisposerCalls = 0 const store = observable({ prop1: 0, prop2: 0 }) - const Component = observer((props: { store: typeof store }) => { - useDisposable(() => { - const disposer = reaction( - () => props.store.prop1, - () => { - reactions1++ + let firstReaction!: () => void + + const Component = observer((props: { store: typeof store; a?: number }) => { + firstReaction = useDisposable( + () => { + reactions1Created++ + const disposer = reaction( + () => props.store.prop1, + () => { + reactions1++ + } + ) + + return () => { + reaction1DisposerCalls++ + disposer() } - ) - - return () => { - reactionDisposerCalls++ - disposer() - } - }) + }, + [props.a] + ) - useDisposable(() => { - const disposer = reaction( - () => props.store.prop2, - () => { - reactions2++ + useDisposable( + () => { + reactions2Created++ + const disposer = reaction( + () => props.store.prop2, + () => { + reactions2++ + } + ) + + return () => { + reaction2DisposerCalls++ + disposer() } - ) - - return () => { - reactionDisposerCalls++ - disposer() - } - }) + }, + [props.a] + ) renders++ return (
- {props.store.prop1} {props.store.prop2} + {props.store.prop1} {props.store.prop2} {props.a}
) }) const { rerender, unmount } = render() - expect(reactionDisposerCalls).toBe(0) + expect(reaction1DisposerCalls).toBe(0) + expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(1) expect(reactions1).toBe(0) expect(reactions2).toBe(0) + expect(reactions1Created).toBe(1) + expect(reactions2Created).toBe(1) store.prop1 = 1 rerender() - expect(reactionDisposerCalls).toBe(0) + expect(reaction1DisposerCalls).toBe(0) + expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(2) expect(reactions1).toBe(1) expect(reactions2).toBe(0) + expect(reactions1Created).toBe(1) + expect(reactions2Created).toBe(1) store.prop2 = 1 rerender() - expect(reactionDisposerCalls).toBe(0) + expect(reaction1DisposerCalls).toBe(0) + expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(3) expect(reactions1).toBe(1) expect(reactions2).toBe(1) + expect(reactions1Created).toBe(1) + expect(reactions2Created).toBe(1) + + // early dispose one of them, it shouldn't be re-created when one of the dependent inputs change + firstReaction() + expect(reaction1DisposerCalls).toBe(1) // early disposal + expect(reaction2DisposerCalls).toBe(0) // this one is not early disposed + + rerender() + expect(reaction1DisposerCalls).toBe(1) // depends on a, but was early disposed, so it should not increment + expect(reaction2DisposerCalls).toBe(1) // depends on a, so it gets re-created + expect(renders).toBe(4) + expect(reactions1).toBe(1) + expect(reactions2).toBe(1) + expect(reactions1Created).toBe(1) + expect(reactions2Created).toBe(2) unmount() - expect(reactionDisposerCalls).toBe(2) - expect(renders).toBe(3) + expect(reaction1DisposerCalls).toBe(1) + expect(reaction2DisposerCalls).toBe(2) + expect(renders).toBe(4) expect(reactions1).toBe(1) expect(reactions2).toBe(1) + expect(reactions1Created).toBe(1) + expect(reactions2Created).toBe(2) }) test("disposer needs to be a function", async () => { From 606d9880c8e55fed280aa7ba89ead5018707f9ec Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 21:11:51 +0100 Subject: [PATCH 4/8] making unit test a bit more clear --- test/useDisposable.test.tsx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/useDisposable.test.tsx b/test/useDisposable.test.tsx index dc780bca..c2b57840 100644 --- a/test/useDisposable.test.tsx +++ b/test/useDisposable.test.tsx @@ -68,56 +68,58 @@ test("reactions run and dispose properly", async () => { }) const { rerender, unmount } = render() + expect(reactions1Created).toBe(1) expect(reaction1DisposerCalls).toBe(0) + expect(reactions2Created).toBe(1) expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(1) expect(reactions1).toBe(0) expect(reactions2).toBe(0) - expect(reactions1Created).toBe(1) - expect(reactions2Created).toBe(1) store.prop1 = 1 rerender() + expect(reactions1Created).toBe(1) expect(reaction1DisposerCalls).toBe(0) + expect(reactions2Created).toBe(1) expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(2) expect(reactions1).toBe(1) expect(reactions2).toBe(0) - expect(reactions1Created).toBe(1) - expect(reactions2Created).toBe(1) store.prop2 = 1 rerender() + expect(reactions1Created).toBe(1) expect(reaction1DisposerCalls).toBe(0) + expect(reactions2Created).toBe(1) expect(reaction2DisposerCalls).toBe(0) expect(renders).toBe(3) expect(reactions1).toBe(1) expect(reactions2).toBe(1) - expect(reactions1Created).toBe(1) - expect(reactions2Created).toBe(1) // early dispose one of them, it shouldn't be re-created when one of the dependent inputs change firstReaction() + expect(reactions1Created).toBe(1) expect(reaction1DisposerCalls).toBe(1) // early disposal + expect(reactions2Created).toBe(1) expect(reaction2DisposerCalls).toBe(0) // this one is not early disposed rerender() - expect(reaction1DisposerCalls).toBe(1) // depends on a, but was early disposed, so it should not increment - expect(reaction2DisposerCalls).toBe(1) // depends on a, so it gets re-created + expect(reactions1Created).toBe(1) // depends on a, but was early disposed, so it should not increment + expect(reaction1DisposerCalls).toBe(1) + expect(reactions2Created).toBe(2) // depends on a, so it gets re-created + expect(reaction2DisposerCalls).toBe(1) expect(renders).toBe(4) expect(reactions1).toBe(1) expect(reactions2).toBe(1) - expect(reactions1Created).toBe(1) - expect(reactions2Created).toBe(2) unmount() + expect(reactions1Created).toBe(1) expect(reaction1DisposerCalls).toBe(1) + expect(reactions2Created).toBe(2) expect(reaction2DisposerCalls).toBe(2) expect(renders).toBe(4) expect(reactions1).toBe(1) expect(reactions2).toBe(1) - expect(reactions1Created).toBe(1) - expect(reactions2Created).toBe(2) }) test("disposer needs to be a function", async () => { From c797af856d5c6a1a63190fca69662489a9188545 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 23:36:36 +0100 Subject: [PATCH 5/8] code review fixes --- src/useDisposable.ts | 24 ++++++++++++++---------- test/useDisposable.test.tsx | 26 ++++++++++++++++---------- test/useObservableEffect.test.tsx | 14 +++++--------- test/utils.ts | 14 ++++++++++++++ 4 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 test/utils.ts diff --git a/src/useDisposable.ts b/src/useDisposable.ts index ef625f63..b21f26fa 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -20,30 +20,34 @@ export function useDisposable( disposerGenerator: () => D, inputs: ReadonlyArray = [] ): D { - const disposer = useRef(undefined) - const earlyDisposed = useRef(false) + const disposerRef = useRef(undefined) + const earlyDisposedRef = useRef(false) // we need to use layout effect since disposals need to be run synchronously useLayoutEffect(() => { return lazyCreateDisposer(false) }, inputs) - const lazyCreateDisposer = (earlyDisposal: boolean) => { + function lazyCreateDisposer(earlyDisposal: boolean) { // ensure that we won't create a new disposer if it was early disposed - if (earlyDisposed.current) { + if (earlyDisposedRef.current) { return doNothingDisposer } - if (!disposer.current) { - disposer.current = disposerGenerator() + if (!disposerRef.current) { + disposerRef.current = disposerGenerator() + if (typeof disposerRef.current !== "function") { + disposerRef.current = undefined + throw new Error("generated disposer must be a function") + } } return () => { - if (typeof disposer.current === "function") { - disposer.current() + if (disposerRef.current) { + disposerRef.current() + disposerRef.current = undefined } - disposer.current = undefined if (earlyDisposal) { - earlyDisposed.current = true + earlyDisposedRef.current = true } } } diff --git a/test/useDisposable.test.tsx b/test/useDisposable.test.tsx index c2b57840..f6969120 100644 --- a/test/useDisposable.test.tsx +++ b/test/useDisposable.test.tsx @@ -3,6 +3,7 @@ import * as React from "react" import { cleanup, render } from "react-testing-library" import { observer, useDisposable } from "../src" +import { withoutConsoleError } from "./utils" afterEach(cleanup) @@ -122,25 +123,30 @@ test("reactions run and dispose properly", async () => { expect(reactions2).toBe(1) }) -test("disposer needs to be a function", async () => { - let renders = 0 +test("disposer needs to be a function or else throws", async () => { + const error = "generated disposer must be a function" - const Component = observer(() => { + const Component1 = observer(() => { useDisposable(() => { return undefined as any }) + return
test
+ }) + const Component2 = observer(() => { useDisposable(() => { - return "I am not a disposer" as any + return "string" as any }) - - renders++ return
test
}) - const { unmount } = render() - expect(renders).toBe(1) + await withoutConsoleError(async () => { + expect(() => { + render() + }).toThrow(error) - unmount() - expect(renders).toBe(1) + expect(() => { + render() + }).toThrow(error) + }) }) diff --git a/test/useObservableEffect.test.tsx b/test/useObservableEffect.test.tsx index b6b02fb8..1b4a789c 100644 --- a/test/useObservableEffect.test.tsx +++ b/test/useObservableEffect.test.tsx @@ -2,6 +2,7 @@ import { IReactionDisposer, observable, reaction } from "mobx" import * as React from "react" import { cleanup, render } from "react-testing-library" import { observer, useObservableEffect } from "../src" +import { withoutConsoleError } from "./utils" afterEach(cleanup) @@ -80,21 +81,16 @@ test("reactions run and dispose properly", async () => { expect(reactions2).toBe(1) }) -test("an undefined disposer works", async () => { - let renders = 0 - +test("an undefined disposer throws", async () => { const Component = observer(() => { useObservableEffect(() => { return undefined as any }) - renders++ return
test
}) - const { rerender } = render() - expect(renders).toBe(1) - - rerender(
) - expect(renders).toBe(1) + await withoutConsoleError(async () => { + expect(() => render()).toThrow("generated disposer must be a function") + }) }) diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 00000000..68c676da --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,14 @@ +export async function withoutConsoleError(fn: () => Promise) { + // tslint:disable:no-console + const original = console.error + console.error = () => { + // do nothing + } + + try { + await fn() + } finally { + console.error = original + } + // tslint:enable:no-console +} From 42dbe8e32e35794da6b70e823f87eb1b7e705e63 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Jan 2019 23:51:10 +0100 Subject: [PATCH 6/8] small change --- src/useDisposable.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/useDisposable.ts b/src/useDisposable.ts index b21f26fa..a147e26b 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -35,11 +35,11 @@ export function useDisposable( } if (!disposerRef.current) { - disposerRef.current = disposerGenerator() - if (typeof disposerRef.current !== "function") { - disposerRef.current = undefined + const newDisposer = disposerGenerator() + if (typeof newDisposer !== "function") { throw new Error("generated disposer must be a function") } + disposerRef.current = newDisposer } return () => { if (disposerRef.current) { From 80fdfc9e9451b50fd9a52dd352bde7b097b119e8 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Fri, 18 Jan 2019 17:52:12 +0100 Subject: [PATCH 7/8] more code review fixes --- package.json | 2 +- src/useDisposable.ts | 15 +++++++++++---- src/utils.ts | 4 ++-- test/useDisposable.test.tsx | 25 +++++++++++++++---------- test/useObservableEffect.test.tsx | 15 ++++++++++----- test/utils.ts | 14 -------------- yarn.lock | 2 +- 7 files changed, 40 insertions(+), 37 deletions(-) delete mode 100644 test/utils.ts diff --git a/package.json b/package.json index 0337e4f6..793a7824 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "jest": "^23.6.0", "jest-dom": "^3.0.0", "jest-environment-jsdom": "^23.4.0", - "jest-mock-console": "^0.4.0", + "jest-mock-console": "^0.4.2", "lint-staged": "^8.0.4", "lodash": "^4.17.11", "mobx": "^5.0.0", diff --git a/src/useDisposable.ts b/src/useDisposable.ts index a147e26b..c75e15ca 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -1,4 +1,4 @@ -import { useLayoutEffect, useRef } from "react" +import { useEffect, useRef } from "react" type TDisposable = () => void @@ -23,8 +23,7 @@ export function useDisposable( const disposerRef = useRef(undefined) const earlyDisposedRef = useRef(false) - // we need to use layout effect since disposals need to be run synchronously - useLayoutEffect(() => { + useEffect(() => { return lazyCreateDisposer(false) }, inputs) @@ -36,9 +35,17 @@ export function useDisposable( if (!disposerRef.current) { const newDisposer = disposerGenerator() + if (typeof newDisposer !== "function") { - throw new Error("generated disposer must be a function") + if (process.env.NODE_ENV !== "production") { + throw new Error("generated disposer must be a function") + } else { + // tslint:disable-next-line:no-console + console.error("generated disposer must be a function") + return doNothingDisposer + } } + disposerRef.current = newDisposer } return () => { diff --git a/src/utils.ts b/src/utils.ts index 52e3a019..7480a1ef 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ -import { useLayoutEffect } from "react" +import { useEffect } from "react" const EMPTY_ARRAY: any[] = [] export function useUnmount(fn: () => void) { - useLayoutEffect(() => fn, EMPTY_ARRAY) + useEffect(() => fn, EMPTY_ARRAY) } diff --git a/test/useDisposable.test.tsx b/test/useDisposable.test.tsx index f6969120..53522764 100644 --- a/test/useDisposable.test.tsx +++ b/test/useDisposable.test.tsx @@ -1,9 +1,9 @@ +import mockConsole from "jest-mock-console" import { observable, reaction } from "mobx" import * as React from "react" -import { cleanup, render } from "react-testing-library" +import { cleanup, flushEffects, render } from "react-testing-library" import { observer, useDisposable } from "../src" -import { withoutConsoleError } from "./utils" afterEach(cleanup) @@ -105,6 +105,7 @@ test("reactions run and dispose properly", async () => { expect(reaction2DisposerCalls).toBe(0) // this one is not early disposed rerender() + flushEffects() expect(reactions1Created).toBe(1) // depends on a, but was early disposed, so it should not increment expect(reaction1DisposerCalls).toBe(1) expect(reactions2Created).toBe(2) // depends on a, so it gets re-created @@ -140,13 +141,17 @@ test("disposer needs to be a function or else throws", async () => { return
test
}) - await withoutConsoleError(async () => { - expect(() => { - render() - }).toThrow(error) + const restoreConsole = mockConsole() - expect(() => { - render() - }).toThrow(error) - }) + expect(() => { + render() + flushEffects() + }).toThrow(error) + + expect(() => { + render() + flushEffects() + }).toThrow(error) + + restoreConsole() }) diff --git a/test/useObservableEffect.test.tsx b/test/useObservableEffect.test.tsx index 1b4a789c..08314010 100644 --- a/test/useObservableEffect.test.tsx +++ b/test/useObservableEffect.test.tsx @@ -1,8 +1,8 @@ +import mockConsole from "jest-mock-console" import { IReactionDisposer, observable, reaction } from "mobx" import * as React from "react" -import { cleanup, render } from "react-testing-library" +import { cleanup, flushEffects, render } from "react-testing-library" import { observer, useObservableEffect } from "../src" -import { withoutConsoleError } from "./utils" afterEach(cleanup) @@ -90,7 +90,12 @@ test("an undefined disposer throws", async () => { return
test
}) - await withoutConsoleError(async () => { - expect(() => render()).toThrow("generated disposer must be a function") - }) + const restoreConsole = mockConsole() + + expect(() => { + render() + flushEffects() + }).toThrow("generated disposer must be a function") + + restoreConsole() }) diff --git a/test/utils.ts b/test/utils.ts deleted file mode 100644 index 68c676da..00000000 --- a/test/utils.ts +++ /dev/null @@ -1,14 +0,0 @@ -export async function withoutConsoleError(fn: () => Promise) { - // tslint:disable:no-console - const original = console.error - console.error = () => { - // do nothing - } - - try { - await fn() - } finally { - console.error = original - } - // tslint:enable:no-console -} diff --git a/yarn.lock b/yarn.lock index e33dab8c..4340c34d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2421,7 +2421,7 @@ jest-message-util@^23.4.0: slash "^1.0.0" stack-utils "^1.0.1" -jest-mock-console@^0.4.0: +jest-mock-console@^0.4.2: version "0.4.2" resolved "https://registry.yarnpkg.com/jest-mock-console/-/jest-mock-console-0.4.2.tgz#6caf471a66cdb88222ae09a4520af192176765f6" integrity sha512-24ryiWYf/pmvOLlelLg4+K2umMI4IFcLls1hluJzs22jGVXzdqpfcMMSXaWdAzbTJ+C0qlSdvj06fqvqFyRO1A== From 3dfd822d9ee67d86e8f1e980ab28d7c6141a5eb3 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Sat, 19 Jan 2019 12:13:04 +0100 Subject: [PATCH 8/8] test for prod mode --- src/useDisposable.ts | 5 +++-- test/useDisposable.test.tsx | 16 +++++++++++++++- test/utils.ts | 10 ++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/utils.ts diff --git a/src/useDisposable.ts b/src/useDisposable.ts index c75e15ca..b2d547fd 100644 --- a/src/useDisposable.ts +++ b/src/useDisposable.ts @@ -37,11 +37,12 @@ export function useDisposable( const newDisposer = disposerGenerator() if (typeof newDisposer !== "function") { + const error = new Error("generated disposer must be a function") if (process.env.NODE_ENV !== "production") { - throw new Error("generated disposer must be a function") + throw error } else { // tslint:disable-next-line:no-console - console.error("generated disposer must be a function") + console.error(error) return doNothingDisposer } } diff --git a/test/useDisposable.test.tsx b/test/useDisposable.test.tsx index 53522764..817ff6fe 100644 --- a/test/useDisposable.test.tsx +++ b/test/useDisposable.test.tsx @@ -4,6 +4,7 @@ import * as React from "react" import { cleanup, flushEffects, render } from "react-testing-library" import { observer, useDisposable } from "../src" +import { productionMode } from "./utils" afterEach(cleanup) @@ -124,7 +125,7 @@ test("reactions run and dispose properly", async () => { expect(reactions2).toBe(1) }) -test("disposer needs to be a function or else throws", async () => { +test("disposer needs to be a function or else throws/console.error", async () => { const error = "generated disposer must be a function" const Component1 = observer(() => { @@ -142,6 +143,8 @@ test("disposer needs to be a function or else throws", async () => { }) const restoreConsole = mockConsole() + // tslint:disable-next-line:no-console + const mockConsoleError = console.error as jest.Mock<{}> expect(() => { render() @@ -153,5 +156,16 @@ test("disposer needs to be a function or else throws", async () => { flushEffects() }).toThrow(error) + productionMode(() => { + mockConsoleError.mockClear() + render() + flushEffects() + expect(mockConsoleError.mock.calls[0][0].message).toEqual(error) + + mockConsoleError.mockClear() + render() + flushEffects() + expect(mockConsoleError.mock.calls[0][0].message).toEqual(error) + }) restoreConsole() }) diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 00000000..a4e5978e --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,10 @@ +export function productionMode(fn: () => void) { + const oldNodeEnv = process.env.NODE_ENV + process.env.NODE_ENV = "production" + + try { + fn() + } finally { + process.env.NODE_ENV = oldNodeEnv + } +}