diff --git a/README.md b/README.md index da179dd..7192ee5 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,16 @@ export default function HotCarDeals() { - **staleAfter** _(900000 i.e. 15 minutes)_: an interval of time after which a successfully fetched item will try to refresh itself (e.g. turn `select${Name}IsPendingForFetch` back on). Falsie value or `Infinity` will disable staling mechanism. - **expireAfter** _(`Infinity`)_: similar to `staleAfter` but will hard-remove the item from the store, resetting it to pristine state. Useful with caching to to prevent app user to see really old data when re-opening the page. - **persist** _(true)_: will instruct `cacheBundle` to cache on meaningful updates. +- **dependencyKey** _(null)_: when given, will listen for values of related selectors: + - as an example, dependency key `userId` will listen to selector `selectUserId` + - when dependency selector resolves with `null` or `undefined`, it will prevent resource from fetching + - when dependency selector resolves to a value, this value will be mixed-in into `getPromise` parameters + - when resolved value changes, bundle will force-clear itself + - example values used in most cases: `currentUserId` or `['myResourceListPage', 'myResourceListPageSize']'` + - as shown above, to listen to several selectors, pass an array + - rather than a simple string, each selector can be represented as an object with additional parameters (i.e. `{ key: 'userId', staleOnChange: true '}`): + - **staleOnChange**: _(false)_ - if `true`, will stale a resource when dependency changes, rather than clearing the store + - **allowBlank**: _(false)_ – if `true`, will not lock resource from fetching when resolved value is `null` or `undefined` #### Selectors @@ -89,12 +99,12 @@ export default function HotCarDeals() { - `select${Name}` – returns item data or `undefined` if there's nothing there - `select${Name}IsPresent` – returns `true` if there is something to be returned by `select${Name}` (i.e. there was at least one successful load before) - `select${Name}IsLoading` – returns `true` if item is currently loading (irrelevant of whether there is some data or not in `select${Name}`) -- `select${Name}IsPendingForFetch` – returns `true` if resource thinks it should load now (i.e. pristine or stale or there was an error and `retryAfter` has passed) +- `select${Name}IsPendingForFetch` – returns `true` if resource thinks it should load now (i.e. pristine or stale or there was an error and `retryAfter` has passed or dependencies were specified and changed) - `select${Name}Error` – returns whatever `gerPromise` rejected with previously; reset to `null` or new error value after next load is finished - `select${Name}IsReadyForRetry` – returns `true` if previous fetch resulted in error and `retryAfter` has passed - `select${Name}RetryAt` – returns `null` or a timestamp at which item fetch will be retried - `select${Name}ErrorIsPermanent` – returns `true` if previous fetch resulted in error and error object had `permanent` field on -- `select${Name}IsStale` – returns `true` if item is stale (manually or respective interval has passed) +- `select${Name}IsStale` – returns `true` if item is stale (manually or respective interval has passed) #### Action Creators @@ -103,6 +113,8 @@ export default function HotCarDeals() { - `doMark${Name}AsStale` – force-mark resource as outdated. Will not remove item from the bundle, but will turn "refetch me!" flag on. - `doAdjust${Name}(payload)` – if there is some data present, replace item data with specified `payload`. If `payload` is a function, call it a with single parameter (current data value), and replace data with that it returns. Primary use case is when you have some mutation API calls to your resource that always render a predictable change of your resource properties – so you want to save up on re-fetching it and just update in place. +... some other selectors and action creators are present, though mostly technical and are needed for bundle functioning + ### createAsyncResourcesBundle ##### createStore.js @@ -244,6 +256,8 @@ In (rare) cases when you need to async resources in a resource-agnostic manner, Calling this with a resource `name` will return you an object of the following shape (assuming resource name `"myResource"`): +(similar to) + ```json { "selectors": { @@ -282,7 +296,7 @@ Calling this with a resource `name` will return you an object of the following s } ``` -... and for `makeAsyncResourcesBundleKeys` it will be: +... and for `makeAsyncResourcesBundleKeys` it will be similar to: ```json { diff --git a/package-lock.json b/package-lock.json index b541fd1..4b8629a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "redux-bundler-async-resources", - "version": "1.1.1", + "version": "1.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -829,32 +829,32 @@ } }, "@jest/core": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/core/-/core-24.7.1.tgz", - "integrity": "sha512-ivlZ8HX/FOASfHcb5DJpSPFps8ydfUYzLZfgFFqjkLijYysnIEOieg72YRhO4ZUB32xu40hsSMmaw+IGYeKONA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/core/-/core-24.8.0.tgz", + "integrity": "sha512-R9rhAJwCBQzaRnrRgAdVfnglUuATXdwTRsYqs6NMdVcAl5euG8LtWDe+fVkN27YfKVBW61IojVsXKaOmSnqd/A==", "dev": true, "requires": { "@jest/console": "^24.7.1", - "@jest/reporters": "^24.7.1", - "@jest/test-result": "^24.7.1", - "@jest/transform": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/reporters": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/transform": "^24.8.0", + "@jest/types": "^24.8.0", "ansi-escapes": "^3.0.0", "chalk": "^2.0.1", "exit": "^0.1.2", "graceful-fs": "^4.1.15", - "jest-changed-files": "^24.7.0", - "jest-config": "^24.7.1", - "jest-haste-map": "^24.7.1", - "jest-message-util": "^24.7.1", + "jest-changed-files": "^24.8.0", + "jest-config": "^24.8.0", + "jest-haste-map": "^24.8.0", + "jest-message-util": "^24.8.0", "jest-regex-util": "^24.3.0", - "jest-resolve-dependencies": "^24.7.1", - "jest-runner": "^24.7.1", - "jest-runtime": "^24.7.1", - "jest-snapshot": "^24.7.1", - "jest-util": "^24.7.1", - "jest-validate": "^24.7.0", - "jest-watcher": "^24.7.1", + "jest-resolve-dependencies": "^24.8.0", + "jest-runner": "^24.8.0", + "jest-runtime": "^24.8.0", + "jest-snapshot": "^24.8.0", + "jest-util": "^24.8.0", + "jest-validate": "^24.8.0", + "jest-watcher": "^24.8.0", "micromatch": "^3.1.10", "p-each-series": "^1.0.0", "pirates": "^4.0.1", @@ -864,49 +864,50 @@ } }, "@jest/environment": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-24.7.1.tgz", - "integrity": "sha512-wmcTTYc4/KqA+U5h1zQd5FXXynfa7VGP2NfF+c6QeGJ7c+2nStgh65RQWNX62SC716dTtqheTRrZl0j+54oGHw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-24.8.0.tgz", + "integrity": "sha512-vlGt2HLg7qM+vtBrSkjDxk9K0YtRBi7HfRFaDxoRtyi+DyVChzhF20duvpdAnKVBV6W5tym8jm0U9EfXbDk1tw==", "dev": true, "requires": { - "@jest/fake-timers": "^24.7.1", - "@jest/transform": "^24.7.1", - "@jest/types": "^24.7.0", - "jest-mock": "^24.7.0" + "@jest/fake-timers": "^24.8.0", + "@jest/transform": "^24.8.0", + "@jest/types": "^24.8.0", + "jest-mock": "^24.8.0" } }, "@jest/fake-timers": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-24.7.1.tgz", - "integrity": "sha512-4vSQJDKfR2jScOe12L9282uiwuwQv9Lk7mgrCSZHA9evB9efB/qx8i0KJxsAKtp8fgJYBJdYY7ZU6u3F4/pyjA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-24.8.0.tgz", + "integrity": "sha512-2M4d5MufVXwi6VzZhJ9f5S/wU4ud2ck0kxPof1Iz3zWx6Y+V2eJrES9jEktB6O3o/oEyk+il/uNu9PvASjWXQw==", "dev": true, "requires": { - "@jest/types": "^24.7.0", - "jest-message-util": "^24.7.1", - "jest-mock": "^24.7.0" + "@jest/types": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-mock": "^24.8.0" } }, "@jest/reporters": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-24.7.1.tgz", - "integrity": "sha512-bO+WYNwHLNhrjB9EbPL4kX/mCCG4ZhhfWmO3m4FSpbgr7N83MFejayz30kKjgqr7smLyeaRFCBQMbXpUgnhAJw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-24.8.0.tgz", + "integrity": "sha512-eZ9TyUYpyIIXfYCrw0UHUWUvE35vx5I92HGMgS93Pv7du+GHIzl+/vh8Qj9MCWFK/4TqyttVBPakWMOfZRIfxw==", "dev": true, "requires": { - "@jest/environment": "^24.7.1", - "@jest/test-result": "^24.7.1", - "@jest/transform": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/environment": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/transform": "^24.8.0", + "@jest/types": "^24.8.0", "chalk": "^2.0.1", "exit": "^0.1.2", "glob": "^7.1.2", - "istanbul-api": "^2.1.1", "istanbul-lib-coverage": "^2.0.2", "istanbul-lib-instrument": "^3.0.1", + "istanbul-lib-report": "^2.0.4", "istanbul-lib-source-maps": "^3.0.1", - "jest-haste-map": "^24.7.1", - "jest-resolve": "^24.7.1", - "jest-runtime": "^24.7.1", - "jest-util": "^24.7.1", + "istanbul-reports": "^2.1.1", + "jest-haste-map": "^24.8.0", + "jest-resolve": "^24.8.0", + "jest-runtime": "^24.8.0", + "jest-util": "^24.8.0", "jest-worker": "^24.6.0", "node-notifier": "^5.2.1", "slash": "^2.0.0", @@ -942,44 +943,44 @@ } }, "@jest/test-result": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-24.7.1.tgz", - "integrity": "sha512-3U7wITxstdEc2HMfBX7Yx3JZgiNBubwDqQMh+BXmZXHa3G13YWF3p6cK+5g0hGkN3iufg/vGPl3hLxQXD74Npg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-24.8.0.tgz", + "integrity": "sha512-+YdLlxwizlfqkFDh7Mc7ONPQAhA4YylU1s529vVM1rsf67vGZH/2GGm5uO8QzPeVyaVMobCQ7FTxl38QrKRlng==", "dev": true, "requires": { "@jest/console": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "@types/istanbul-lib-coverage": "^2.0.0" } }, "@jest/test-sequencer": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-24.7.1.tgz", - "integrity": "sha512-84HQkCpVZI/G1zq53gHJvSmhUer4aMYp9tTaffW28Ih5OxfCg8hGr3nTSbL1OhVDRrFZwvF+/R9gY6JRkDUpUA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-24.8.0.tgz", + "integrity": "sha512-OzL/2yHyPdCHXEzhoBuq37CE99nkme15eHkAzXRVqthreWZamEMA0WoetwstsQBCXABhczpK03JNbc4L01vvLg==", "dev": true, "requires": { - "@jest/test-result": "^24.7.1", - "jest-haste-map": "^24.7.1", - "jest-runner": "^24.7.1", - "jest-runtime": "^24.7.1" + "@jest/test-result": "^24.8.0", + "jest-haste-map": "^24.8.0", + "jest-runner": "^24.8.0", + "jest-runtime": "^24.8.0" } }, "@jest/transform": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-24.7.1.tgz", - "integrity": "sha512-EsOUqP9ULuJ66IkZQhI5LufCHlTbi7hrcllRMUEV/tOgqBVQi93+9qEvkX0n8mYpVXQ8VjwmICeRgg58mrtIEw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-24.8.0.tgz", + "integrity": "sha512-xBMfFUP7TortCs0O+Xtez2W7Zu1PLH9bvJgtraN1CDST6LBM/eTOZ9SfwS/lvV8yOfcDpFmwf9bq5cYbXvqsvA==", "dev": true, "requires": { "@babel/core": "^7.1.0", - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "babel-plugin-istanbul": "^5.1.0", "chalk": "^2.0.1", "convert-source-map": "^1.4.0", "fast-json-stable-stringify": "^2.0.0", "graceful-fs": "^4.1.15", - "jest-haste-map": "^24.7.1", + "jest-haste-map": "^24.8.0", "jest-regex-util": "^24.3.0", - "jest-util": "^24.7.1", + "jest-util": "^24.8.0", "micromatch": "^3.1.10", "realpath-native": "^1.1.0", "slash": "^2.0.0", @@ -996,19 +997,20 @@ } }, "@jest/types": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-24.7.0.tgz", - "integrity": "sha512-ipJUa2rFWiKoBqMKP63Myb6h9+iT3FHRTF2M8OR6irxWzItisa8i4dcSg14IbvmXUnBlHBlUQPYUHWyX3UPpYA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-24.8.0.tgz", + "integrity": "sha512-g17UxVr2YfBtaMUxn9u/4+siG1ptg9IGYAYwvpwn61nBg779RXnjE/m7CxYcIzEt0AbHZZAHSEZNhkE2WxURVg==", "dev": true, "requires": { "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^1.1.1", "@types/yargs": "^12.0.9" } }, "@types/babel__core": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.1.tgz", - "integrity": "sha512-+hjBtgcFPYyCTo0A15+nxrCVJL7aC6Acg87TXd5OW3QhHswdrOLoles+ldL2Uk8q++7yIfl4tURtztccdeeyOw==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.2.tgz", + "integrity": "sha512-cfCCrFmiGY/yq0NuKNxIQvZFy9kY/1immpSpTngOnyIbD4+eJOG5mxphhHDv3CHL9GltO4GcKr54kGBg3RNdbg==", "dev": true, "requires": { "@babel/parser": "^7.1.0", @@ -1058,6 +1060,25 @@ "integrity": "sha512-hRJD2ahnnpLgsj6KWMYSrmXkM3rm2Dl1qkx6IOFD5FnuNPXJIG5L0dhgKXCYTRMGzU4n0wImQ/xfmRc4POUFlg==", "dev": true }, + "@types/istanbul-lib-report": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-1.1.1.tgz", + "integrity": "sha512-3BUTyMzbZa2DtDI2BkERNC6jJw2Mr2Y0oGI7mRxYNBPxppbtEK1F66u3bKwU2g+wxwWI7PAoRpJnOY1grJqzHg==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "*" + } + }, + "@types/istanbul-reports": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-1.1.1.tgz", + "integrity": "sha512-UpYjBi8xefVChsCoBpKShdxTllC9pwISirfoZsUa2AAdQg/Jd2KQGtSbw+ya7GPo7x/wAPlH6JBhKhAsXUEZNA==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "*", + "@types/istanbul-lib-report": "*" + } + }, "@types/node": { "version": "11.13.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.9.tgz", @@ -1188,15 +1209,6 @@ "normalize-path": "^2.1.1" } }, - "append-transform": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", - "integrity": "sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==", - "dev": true, - "requires": { - "default-require-extensions": "^2.0.0" - } - }, "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", @@ -1279,15 +1291,6 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, - "async": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz", - "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", - "dev": true, - "requires": { - "lodash": "^4.17.11" - } - }, "async-limiter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", @@ -1339,13 +1342,13 @@ "dev": true }, "babel-jest": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.7.1.tgz", - "integrity": "sha512-GPnLqfk8Mtt0i4OemjWkChi73A3ALs4w2/QbG64uAj8b5mmwzxc7jbJVRZt8NJkxi6FopVHog9S3xX6UJKb2qg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.8.0.tgz", + "integrity": "sha512-+5/kaZt4I9efoXzPlZASyK/lN9qdRKmmUav9smVc0ruPQD7IsfucQ87gpOE8mn2jbDuS6M/YOW6n3v9ZoIfgnw==", "dev": true, "requires": { - "@jest/transform": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/transform": "^24.8.0", + "@jest/types": "^24.8.0", "@types/babel__core": "^7.1.0", "babel-plugin-istanbul": "^5.1.0", "babel-preset-jest": "^24.6.0", @@ -1970,9 +1973,9 @@ "dev": true }, "combined-stream": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", - "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dev": true, "requires": { "delayed-stream": "~1.0.0" @@ -1984,12 +1987,6 @@ "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", "dev": true }, - "compare-versions": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.4.0.tgz", - "integrity": "sha512-tK69D7oNXXqUW3ZNo/z7NXTEz22TCF0pTE+YF9cxvaAM9XnkLo1fV621xCLrRR6aevJlKxExkss0vWqUCUpqdg==", - "dev": true - }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -2494,15 +2491,6 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, - "default-require-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-2.0.0.tgz", - "integrity": "sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=", - "dev": true, - "requires": { - "strip-bom": "^3.0.0" - } - }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -2909,16 +2897,16 @@ "dev": true }, "expect": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/expect/-/expect-24.7.1.tgz", - "integrity": "sha512-mGfvMTPduksV3xoI0xur56pQsg2vJjNf5+a+bXOjqCkiCBbmCayrBbHS/75y9K430cfqyocPr2ZjiNiRx4SRKw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-24.8.0.tgz", + "integrity": "sha512-/zYvP8iMDrzaaxHVa724eJBCKqSHmO0FA7EDkBiRHxg6OipmMn1fN+C8T9L9K8yr7UONkOifu6+LLH+z76CnaA==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "ansi-styles": "^3.2.0", - "jest-get-type": "^24.3.0", - "jest-matcher-utils": "^24.7.0", - "jest-message-util": "^24.7.1", + "jest-get-type": "^24.8.0", + "jest-matcher-utils": "^24.8.0", + "jest-message-util": "^24.8.0", "jest-regex-util": "^24.3.0" } }, @@ -3069,16 +3057,6 @@ "integrity": "sha1-wcS5vuPglyXdsQa3XB4wH+LxiyY=", "dev": true }, - "fileset": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/fileset/-/fileset-2.0.3.tgz", - "integrity": "sha1-jnVIqW08wjJ+5eZ0FocjozO7oqA=", - "dev": true, - "requires": { - "glob": "^7.0.3", - "minimatch": "^3.0.3" - } - }, "filesize": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz", @@ -3850,9 +3828,9 @@ "dev": true }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -4513,42 +4491,12 @@ "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", "dev": true }, - "istanbul-api": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/istanbul-api/-/istanbul-api-2.1.6.tgz", - "integrity": "sha512-x0Eicp6KsShG1k1rMgBAi/1GgY7kFGEBwQpw3PXGEmu+rBcBNhqU8g2DgY9mlepAsLPzrzrbqSgCGANnki4POA==", - "dev": true, - "requires": { - "async": "^2.6.2", - "compare-versions": "^3.4.0", - "fileset": "^2.0.3", - "istanbul-lib-coverage": "^2.0.5", - "istanbul-lib-hook": "^2.0.7", - "istanbul-lib-instrument": "^3.3.0", - "istanbul-lib-report": "^2.0.8", - "istanbul-lib-source-maps": "^3.0.6", - "istanbul-reports": "^2.2.4", - "js-yaml": "^3.13.1", - "make-dir": "^2.1.0", - "minimatch": "^3.0.4", - "once": "^1.4.0" - } - }, "istanbul-lib-coverage": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", "integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==", "dev": true }, - "istanbul-lib-hook": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-2.0.7.tgz", - "integrity": "sha512-vrRztU9VRRFDyC+aklfLoeXyNdTfga2EI3udDGn4cZ6fpSXpHLV9X6CHvfoMCPtggg8zvDDmC4b9xfu0z6/llA==", - "dev": true, - "requires": { - "append-transform": "^1.0.0" - } - }, "istanbul-lib-instrument": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-3.3.0.tgz", @@ -4616,40 +4564,40 @@ } }, "istanbul-reports": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.2.4.tgz", - "integrity": "sha512-QCHGyZEK0bfi9GR215QSm+NJwFKEShbtc7tfbUdLAEzn3kKhLDDZqvljn8rPZM9v8CEOhzL1nlYoO4r1ryl67w==", + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.2.6.tgz", + "integrity": "sha512-SKi4rnMyLBKe0Jy2uUdx28h8oG7ph2PPuQPvIAh31d+Ci+lSiEu4C+h3oBPuJ9+mPKhOyW0M8gY4U5NM1WLeXA==", "dev": true, "requires": { "handlebars": "^4.1.2" } }, "jest": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest/-/jest-24.7.1.tgz", - "integrity": "sha512-AbvRar5r++izmqo5gdbAjTeA6uNRGoNRuj5vHB0OnDXo2DXWZJVuaObiGgtlvhKb+cWy2oYbQSfxv7Q7GjnAtA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-24.8.0.tgz", + "integrity": "sha512-o0HM90RKFRNWmAWvlyV8i5jGZ97pFwkeVoGvPW1EtLTgJc2+jcuqcbbqcSZLE/3f2S5pt0y2ZBETuhpWNl1Reg==", "dev": true, "requires": { "import-local": "^2.0.0", - "jest-cli": "^24.7.1" + "jest-cli": "^24.8.0" }, "dependencies": { "jest-cli": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-24.7.1.tgz", - "integrity": "sha512-32OBoSCVPzcTslGFl6yVCMzB2SqX3IrWwZCY5mZYkb0D2WsogmU3eV2o8z7+gRQa4o4sZPX/k7GU+II7CxM6WQ==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-24.8.0.tgz", + "integrity": "sha512-+p6J00jSMPQ116ZLlHJJvdf8wbjNbZdeSX9ptfHX06/MSNaXmKihQzx5vQcw0q2G6JsdVkUIdWbOWtSnaYs3yA==", "dev": true, "requires": { - "@jest/core": "^24.7.1", - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/core": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "chalk": "^2.0.1", "exit": "^0.1.2", "import-local": "^2.0.0", "is-ci": "^2.0.0", - "jest-config": "^24.7.1", - "jest-util": "^24.7.1", - "jest-validate": "^24.7.0", + "jest-config": "^24.8.0", + "jest-util": "^24.8.0", + "jest-validate": "^24.8.0", "prompts": "^2.0.1", "realpath-native": "^1.1.0", "yargs": "^12.0.2" @@ -4658,51 +4606,51 @@ } }, "jest-changed-files": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-24.7.0.tgz", - "integrity": "sha512-33BgewurnwSfJrW7T5/ZAXGE44o7swLslwh8aUckzq2e17/2Os1V0QU506ZNik3hjs8MgnEMKNkcud442NCDTw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-24.8.0.tgz", + "integrity": "sha512-qgANC1Yrivsq+UrLXsvJefBKVoCsKB0Hv+mBb6NMjjZ90wwxCDmU3hsCXBya30cH+LnPYjwgcU65i6yJ5Nfuug==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "execa": "^1.0.0", "throat": "^4.0.0" } }, "jest-config": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-24.7.1.tgz", - "integrity": "sha512-8FlJNLI+X+MU37j7j8RE4DnJkvAghXmBWdArVzypW6WxfGuxiL/CCkzBg0gHtXhD2rxla3IMOSUAHylSKYJ83g==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-24.8.0.tgz", + "integrity": "sha512-Czl3Nn2uEzVGsOeaewGWoDPD8GStxCpAe0zOYs2x2l0fZAgPbCr3uwUkgNKV3LwE13VXythM946cd5rdGkkBZw==", "dev": true, "requires": { "@babel/core": "^7.1.0", - "@jest/test-sequencer": "^24.7.1", - "@jest/types": "^24.7.0", - "babel-jest": "^24.7.1", + "@jest/test-sequencer": "^24.8.0", + "@jest/types": "^24.8.0", + "babel-jest": "^24.8.0", "chalk": "^2.0.1", "glob": "^7.1.1", - "jest-environment-jsdom": "^24.7.1", - "jest-environment-node": "^24.7.1", - "jest-get-type": "^24.3.0", - "jest-jasmine2": "^24.7.1", + "jest-environment-jsdom": "^24.8.0", + "jest-environment-node": "^24.8.0", + "jest-get-type": "^24.8.0", + "jest-jasmine2": "^24.8.0", "jest-regex-util": "^24.3.0", - "jest-resolve": "^24.7.1", - "jest-util": "^24.7.1", - "jest-validate": "^24.7.0", + "jest-resolve": "^24.8.0", + "jest-util": "^24.8.0", + "jest-validate": "^24.8.0", "micromatch": "^3.1.10", - "pretty-format": "^24.7.0", + "pretty-format": "^24.8.0", "realpath-native": "^1.1.0" } }, "jest-diff": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-24.7.0.tgz", - "integrity": "sha512-ULQZ5B1lWpH70O4xsANC4tf4Ko6RrpwhE3PtG6ERjMg1TiYTC2Wp4IntJVGro6a8HG9luYHhhmF4grF0Pltckg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-24.8.0.tgz", + "integrity": "sha512-wxetCEl49zUpJ/bvUmIFjd/o52J+yWcoc5ZyPq4/W1LUKGEhRYDIbP1KcF6t+PvqNrGAFk4/JhtxDq/Nnzs66g==", "dev": true, "requires": { "chalk": "^2.0.1", "diff-sequences": "^24.3.0", - "jest-get-type": "^24.3.0", - "pretty-format": "^24.7.0" + "jest-get-type": "^24.8.0", + "pretty-format": "^24.8.0" } }, "jest-docblock": { @@ -4715,65 +4663,65 @@ } }, "jest-each": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-24.7.1.tgz", - "integrity": "sha512-4fsS8fEfLa3lfnI1Jw6NxjhyRTgfpuOVTeUZZFyVYqeTa4hPhr2YkToUhouuLTrL2eMGOfpbdMyRx0GQ/VooKA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-24.8.0.tgz", + "integrity": "sha512-NrwK9gaL5+XgrgoCsd9svsoWdVkK4gnvyhcpzd6m487tXHqIdYeykgq3MKI1u4I+5Zf0tofr70at9dWJDeb+BA==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "chalk": "^2.0.1", - "jest-get-type": "^24.3.0", - "jest-util": "^24.7.1", - "pretty-format": "^24.7.0" + "jest-get-type": "^24.8.0", + "jest-util": "^24.8.0", + "pretty-format": "^24.8.0" } }, "jest-environment-jsdom": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-24.7.1.tgz", - "integrity": "sha512-Gnhb+RqE2JuQGb3kJsLF8vfqjt3PHKSstq4Xc8ic+ax7QKo4Z0RWGucU3YV+DwKR3T9SYc+3YCUQEJs8r7+Jxg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-24.8.0.tgz", + "integrity": "sha512-qbvgLmR7PpwjoFjM/sbuqHJt/NCkviuq9vus9NBn/76hhSidO+Z6Bn9tU8friecegbJL8gzZQEMZBQlFWDCwAQ==", "dev": true, "requires": { - "@jest/environment": "^24.7.1", - "@jest/fake-timers": "^24.7.1", - "@jest/types": "^24.7.0", - "jest-mock": "^24.7.0", - "jest-util": "^24.7.1", + "@jest/environment": "^24.8.0", + "@jest/fake-timers": "^24.8.0", + "@jest/types": "^24.8.0", + "jest-mock": "^24.8.0", + "jest-util": "^24.8.0", "jsdom": "^11.5.1" } }, "jest-environment-node": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-24.7.1.tgz", - "integrity": "sha512-GJJQt1p9/C6aj6yNZMvovZuxTUd+BEJprETdvTKSb4kHcw4mFj8777USQV0FJoJ4V3djpOwA5eWyPwfq//PFBA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-24.8.0.tgz", + "integrity": "sha512-vIGUEScd1cdDgR6sqn2M08sJTRLQp6Dk/eIkCeO4PFHxZMOgy+uYLPMC4ix3PEfM5Au/x3uQ/5Tl0DpXXZsJ/Q==", "dev": true, "requires": { - "@jest/environment": "^24.7.1", - "@jest/fake-timers": "^24.7.1", - "@jest/types": "^24.7.0", - "jest-mock": "^24.7.0", - "jest-util": "^24.7.1" + "@jest/environment": "^24.8.0", + "@jest/fake-timers": "^24.8.0", + "@jest/types": "^24.8.0", + "jest-mock": "^24.8.0", + "jest-util": "^24.8.0" } }, "jest-get-type": { - "version": "24.3.0", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-24.3.0.tgz", - "integrity": "sha512-HYF6pry72YUlVcvUx3sEpMRwXEWGEPlJ0bSPVnB3b3n++j4phUEoSPcS6GC0pPJ9rpyPSe4cb5muFo6D39cXow==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-24.8.0.tgz", + "integrity": "sha512-RR4fo8jEmMD9zSz2nLbs2j0zvPpk/KCEz3a62jJWbd2ayNo0cb+KFRxPHVhE4ZmgGJEQp0fosmNz84IfqM8cMQ==", "dev": true }, "jest-haste-map": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-24.7.1.tgz", - "integrity": "sha512-g0tWkzjpHD2qa03mTKhlydbmmYiA2KdcJe762SbfFo/7NIMgBWAA0XqQlApPwkWOF7Cxoi/gUqL0i6DIoLpMBw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-24.8.0.tgz", + "integrity": "sha512-ZBPRGHdPt1rHajWelXdqygIDpJx8u3xOoLyUBWRW28r3tagrgoepPrzAozW7kW9HrQfhvmiv1tncsxqHJO1onQ==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "anymatch": "^2.0.0", "fb-watchman": "^2.0.0", "fsevents": "^1.2.7", "graceful-fs": "^4.1.15", "invariant": "^2.2.4", "jest-serializer": "^24.4.0", - "jest-util": "^24.7.1", + "jest-util": "^24.8.0", "jest-worker": "^24.6.0", "micromatch": "^3.1.10", "sane": "^4.0.3", @@ -4781,59 +4729,59 @@ } }, "jest-jasmine2": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-24.7.1.tgz", - "integrity": "sha512-Y/9AOJDV1XS44wNwCaThq4Pw3gBPiOv/s6NcbOAkVRRUEPu+36L2xoPsqQXsDrxoBerqeyslpn2TpCI8Zr6J2w==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-24.8.0.tgz", + "integrity": "sha512-cEky88npEE5LKd5jPpTdDCLvKkdyklnaRycBXL6GNmpxe41F0WN44+i7lpQKa/hcbXaQ+rc9RMaM4dsebrYong==", "dev": true, "requires": { "@babel/traverse": "^7.1.0", - "@jest/environment": "^24.7.1", - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/environment": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "chalk": "^2.0.1", "co": "^4.6.0", - "expect": "^24.7.1", + "expect": "^24.8.0", "is-generator-fn": "^2.0.0", - "jest-each": "^24.7.1", - "jest-matcher-utils": "^24.7.0", - "jest-message-util": "^24.7.1", - "jest-runtime": "^24.7.1", - "jest-snapshot": "^24.7.1", - "jest-util": "^24.7.1", - "pretty-format": "^24.7.0", + "jest-each": "^24.8.0", + "jest-matcher-utils": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-runtime": "^24.8.0", + "jest-snapshot": "^24.8.0", + "jest-util": "^24.8.0", + "pretty-format": "^24.8.0", "throat": "^4.0.0" } }, "jest-leak-detector": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-24.7.0.tgz", - "integrity": "sha512-zV0qHKZGXtmPVVzT99CVEcHE9XDf+8LwiE0Ob7jjezERiGVljmqKFWpV2IkG+rkFIEUHFEkMiICu7wnoPM/RoQ==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-24.8.0.tgz", + "integrity": "sha512-cG0yRSK8A831LN8lIHxI3AblB40uhv0z+SsQdW3GoMMVcK+sJwrIIyax5tu3eHHNJ8Fu6IMDpnLda2jhn2pD/g==", "dev": true, "requires": { - "pretty-format": "^24.7.0" + "pretty-format": "^24.8.0" } }, "jest-matcher-utils": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-24.7.0.tgz", - "integrity": "sha512-158ieSgk3LNXeUhbVJYRXyTPSCqNgVXOp/GT7O94mYd3pk/8+odKTyR1JLtNOQSPzNi8NFYVONtvSWA/e1RDXg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-24.8.0.tgz", + "integrity": "sha512-lex1yASY51FvUuHgm0GOVj7DCYEouWSlIYmCW7APSqB9v8mXmKSn5+sWVF0MhuASG0bnYY106/49JU1FZNl5hw==", "dev": true, "requires": { "chalk": "^2.0.1", - "jest-diff": "^24.7.0", - "jest-get-type": "^24.3.0", - "pretty-format": "^24.7.0" + "jest-diff": "^24.8.0", + "jest-get-type": "^24.8.0", + "pretty-format": "^24.8.0" } }, "jest-message-util": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-24.7.1.tgz", - "integrity": "sha512-dk0gqVtyqezCHbcbk60CdIf+8UHgD+lmRHifeH3JRcnAqh4nEyPytSc9/L1+cQyxC+ceaeP696N4ATe7L+omcg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-24.8.0.tgz", + "integrity": "sha512-p2k71rf/b6ns8btdB0uVdljWo9h0ovpnEe05ZKWceQGfXYr4KkzgKo3PBi8wdnd9OtNh46VpNIJynUn/3MKm1g==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "@types/stack-utils": "^1.0.1", "chalk": "^2.0.1", "micromatch": "^3.1.10", @@ -4842,12 +4790,12 @@ } }, "jest-mock": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-24.7.0.tgz", - "integrity": "sha512-6taW4B4WUcEiT2V9BbOmwyGuwuAFT2G8yghF7nyNW1/2gq5+6aTqSPcS9lS6ArvEkX55vbPAS/Jarx5LSm4Fng==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-24.8.0.tgz", + "integrity": "sha512-6kWugwjGjJw+ZkK4mDa0Df3sDlUTsV47MSrT0nGQ0RBWJbpODDQ8MHDVtGtUYBne3IwZUhtB7elxHspU79WH3A==", "dev": true, "requires": { - "@jest/types": "^24.7.0" + "@jest/types": "^24.8.0" } }, "jest-pnp-resolver": { @@ -4863,12 +4811,12 @@ "dev": true }, "jest-resolve": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-24.7.1.tgz", - "integrity": "sha512-Bgrc+/UUZpGJ4323sQyj85hV9d+ANyPNu6XfRDUcyFNX1QrZpSoM0kE4Mb2vZMAYTJZsBFzYe8X1UaOkOELSbw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-24.8.0.tgz", + "integrity": "sha512-+hjSzi1PoRvnuOICoYd5V/KpIQmkAsfjFO71458hQ2Whi/yf1GDeBOFj8Gxw4LrApHsVJvn5fmjcPdmoUHaVKw==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "browser-resolve": "^1.11.3", "chalk": "^2.0.1", "jest-pnp-resolver": "^1.2.1", @@ -4876,68 +4824,68 @@ } }, "jest-resolve-dependencies": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-24.7.1.tgz", - "integrity": "sha512-2Eyh5LJB2liNzfk4eo7bD1ZyBbqEJIyyrFtZG555cSWW9xVHxII2NuOkSl1yUYTAYCAmM2f2aIT5A7HzNmubyg==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-24.8.0.tgz", + "integrity": "sha512-hyK1qfIf/krV+fSNyhyJeq3elVMhK9Eijlwy+j5jqmZ9QsxwKBiP6qukQxaHtK8k6zql/KYWwCTQ+fDGTIJauw==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "jest-regex-util": "^24.3.0", - "jest-snapshot": "^24.7.1" + "jest-snapshot": "^24.8.0" } }, "jest-runner": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-24.7.1.tgz", - "integrity": "sha512-aNFc9liWU/xt+G9pobdKZ4qTeG/wnJrJna3VqunziDNsWT3EBpmxXZRBMKCsNMyfy+A/XHiV+tsMLufdsNdgCw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-24.8.0.tgz", + "integrity": "sha512-utFqC5BaA3JmznbissSs95X1ZF+d+4WuOWwpM9+Ak356YtMhHE/GXUondZdcyAAOTBEsRGAgH/0TwLzfI9h7ow==", "dev": true, "requires": { "@jest/console": "^24.7.1", - "@jest/environment": "^24.7.1", - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/environment": "^24.8.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "chalk": "^2.4.2", "exit": "^0.1.2", "graceful-fs": "^4.1.15", - "jest-config": "^24.7.1", + "jest-config": "^24.8.0", "jest-docblock": "^24.3.0", - "jest-haste-map": "^24.7.1", - "jest-jasmine2": "^24.7.1", - "jest-leak-detector": "^24.7.0", - "jest-message-util": "^24.7.1", - "jest-resolve": "^24.7.1", - "jest-runtime": "^24.7.1", - "jest-util": "^24.7.1", + "jest-haste-map": "^24.8.0", + "jest-jasmine2": "^24.8.0", + "jest-leak-detector": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-resolve": "^24.8.0", + "jest-runtime": "^24.8.0", + "jest-util": "^24.8.0", "jest-worker": "^24.6.0", "source-map-support": "^0.5.6", "throat": "^4.0.0" } }, "jest-runtime": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-24.7.1.tgz", - "integrity": "sha512-0VAbyBy7tll3R+82IPJpf6QZkokzXPIS71aDeqh+WzPRXRCNz6StQ45otFariPdJ4FmXpDiArdhZrzNAC3sj6A==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-24.8.0.tgz", + "integrity": "sha512-Mq0aIXhvO/3bX44ccT+czU1/57IgOMyy80oM0XR/nyD5zgBcesF84BPabZi39pJVA6UXw+fY2Q1N+4BiVUBWOA==", "dev": true, "requires": { "@jest/console": "^24.7.1", - "@jest/environment": "^24.7.1", + "@jest/environment": "^24.8.0", "@jest/source-map": "^24.3.0", - "@jest/transform": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/transform": "^24.8.0", + "@jest/types": "^24.8.0", "@types/yargs": "^12.0.2", "chalk": "^2.0.1", "exit": "^0.1.2", "glob": "^7.1.3", "graceful-fs": "^4.1.15", - "jest-config": "^24.7.1", - "jest-haste-map": "^24.7.1", - "jest-message-util": "^24.7.1", - "jest-mock": "^24.7.0", + "jest-config": "^24.8.0", + "jest-haste-map": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-mock": "^24.8.0", "jest-regex-util": "^24.3.0", - "jest-resolve": "^24.7.1", - "jest-snapshot": "^24.7.1", - "jest-util": "^24.7.1", - "jest-validate": "^24.7.0", + "jest-resolve": "^24.8.0", + "jest-snapshot": "^24.8.0", + "jest-util": "^24.8.0", + "jest-validate": "^24.8.0", "realpath-native": "^1.1.0", "slash": "^2.0.0", "strip-bom": "^3.0.0", @@ -4951,36 +4899,36 @@ "dev": true }, "jest-snapshot": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-24.7.1.tgz", - "integrity": "sha512-8Xk5O4p+JsZZn4RCNUS3pxA+ORKpEKepE+a5ejIKrId9CwrVN0NY+vkqEkXqlstA5NMBkNahXkR/4qEBy0t5yA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-24.8.0.tgz", + "integrity": "sha512-5ehtWoc8oU9/cAPe6fez6QofVJLBKyqkY2+TlKTOf0VllBB/mqUNdARdcjlZrs9F1Cv+/HKoCS/BknT0+tmfPg==", "dev": true, "requires": { "@babel/types": "^7.0.0", - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "chalk": "^2.0.1", - "expect": "^24.7.1", - "jest-diff": "^24.7.0", - "jest-matcher-utils": "^24.7.0", - "jest-message-util": "^24.7.1", - "jest-resolve": "^24.7.1", + "expect": "^24.8.0", + "jest-diff": "^24.8.0", + "jest-matcher-utils": "^24.8.0", + "jest-message-util": "^24.8.0", + "jest-resolve": "^24.8.0", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", - "pretty-format": "^24.7.0", + "pretty-format": "^24.8.0", "semver": "^5.5.0" } }, "jest-util": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-24.7.1.tgz", - "integrity": "sha512-/KilOue2n2rZ5AnEBYoxOXkeTu6vi7cjgQ8MXEkih0oeAXT6JkS3fr7/j8+engCjciOU1Nq5loMSKe0A1oeX0A==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-24.8.0.tgz", + "integrity": "sha512-DYZeE+XyAnbNt0BG1OQqKy/4GVLPtzwGx5tsnDrFcax36rVE3lTA5fbvgmbVPUZf9w77AJ8otqR4VBbfFJkUZA==", "dev": true, "requires": { "@jest/console": "^24.7.1", - "@jest/fake-timers": "^24.7.1", + "@jest/fake-timers": "^24.8.0", "@jest/source-map": "^24.3.0", - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "callsites": "^3.0.0", "chalk": "^2.0.1", "graceful-fs": "^4.1.15", @@ -4999,31 +4947,31 @@ } }, "jest-validate": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-24.7.0.tgz", - "integrity": "sha512-cgai/gts9B2chz1rqVdmLhzYxQbgQurh1PEQSvSgPZ8KGa1AqXsqC45W5wKEwzxKrWqypuQrQxnF4+G9VejJJA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-24.8.0.tgz", + "integrity": "sha512-+/N7VOEMW1Vzsrk3UWBDYTExTPwf68tavEPKDnJzrC6UlHtUDU/fuEdXqFoHzv9XnQ+zW6X3qMZhJ3YexfeLDA==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "camelcase": "^5.0.0", "chalk": "^2.0.1", - "jest-get-type": "^24.3.0", + "jest-get-type": "^24.8.0", "leven": "^2.1.0", - "pretty-format": "^24.7.0" + "pretty-format": "^24.8.0" } }, "jest-watcher": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-24.7.1.tgz", - "integrity": "sha512-Wd6TepHLRHVKLNPacEsBwlp9raeBIO+01xrN24Dek4ggTS8HHnOzYSFnvp+6MtkkJ3KfMzy220KTi95e2rRkrw==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-24.8.0.tgz", + "integrity": "sha512-SBjwHt5NedQoVu54M5GEx7cl7IGEFFznvd/HNT8ier7cCAx/Qgu9ZMlaTQkvK22G1YOpcWBLQPFSImmxdn3DAw==", "dev": true, "requires": { - "@jest/test-result": "^24.7.1", - "@jest/types": "^24.7.0", + "@jest/test-result": "^24.8.0", + "@jest/types": "^24.8.0", "@types/yargs": "^12.0.9", "ansi-escapes": "^3.0.0", "chalk": "^2.0.1", - "jest-util": "^24.7.1", + "jest-util": "^24.8.0", "string-length": "^2.0.0" } }, @@ -5680,9 +5628,9 @@ "dev": true }, "neo-async": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.0.tgz", - "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz", + "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==", "dev": true }, "nice-try": { @@ -7236,9 +7184,9 @@ "dev": true }, "prettier": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", - "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.1.tgz", + "integrity": "sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg==", "dev": true }, "pretty-bytes": { @@ -7248,12 +7196,12 @@ "dev": true }, "pretty-format": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-24.7.0.tgz", - "integrity": "sha512-apen5cjf/U4dj7tHetpC7UEFCvtAgnNZnBDkfPv3fokzIqyOJckAG9OlAPC1BlFALnqT/lGB2tl9EJjlK6eCsA==", + "version": "24.8.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-24.8.0.tgz", + "integrity": "sha512-P952T7dkrDEplsR+TuY7q3VXDae5Sr7zmQb12JU/NDQa/3CH7/QW0yvqLcGN6jL+zQFKaoJcPc+yJxMTGmosqw==", "dev": true, "requires": { - "@jest/types": "^24.7.0", + "@jest/types": "^24.8.0", "ansi-regex": "^4.0.0", "ansi-styles": "^3.2.0", "react-is": "^16.8.4" @@ -10150,9 +10098,9 @@ "dev": true }, "uglify-js": { - "version": "3.5.10", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.10.tgz", - "integrity": "sha512-/GTF0nosyPLbdJBd+AwYiZ+Hu5z8KXWnO0WCGt1BQ/u9Iamhejykqmz5o1OHJ53+VAk6xVxychonnApDjuqGsw==", + "version": "3.5.12", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.12.tgz", + "integrity": "sha512-KeQesOpPiZNgVwJj8Ge3P4JYbQHUdZzpx6Fahy6eKAYRSV4zhVmLXoC+JtOeYxcHCHTve8RG1ZGdTvpeOUM26Q==", "dev": true, "optional": true, "requires": { diff --git a/package.json b/package.json index 5acfa1c..b3acbc6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-bundler-async-resources", - "version": "1.1.1", + "version": "1.2.0", "description": "redux-bundler bundle that manages a collection of async resources", "main": "index.js", "scripts": { @@ -38,10 +38,10 @@ }, "devDependencies": { "@babel/preset-env": "^7.4.4", - "babel-jest": "^24.7.1", - "jest": "^24.7.1", + "babel-jest": "^24.8.0", + "jest": "^24.8.0", "microbundle": "^0.11.0", - "prettier": "^1.17.0", + "prettier": "^1.17.1", "redux-bundler": "^23.1.0", "timekeeper": "^2.2.0" }, diff --git a/src/__tests__/createAsyncResourceBundle.test.js b/src/__tests__/createAsyncResourceBundle.test.js index ed8ee89..f076e9f 100644 --- a/src/__tests__/createAsyncResourceBundle.test.js +++ b/src/__tests__/createAsyncResourceBundle.test.js @@ -410,6 +410,126 @@ describe('createAsyncResourceBundle', () => { }) }) }) + + describe('dependency keys', () => { + describe('with one dependency', () => { + test('does not try to fetch while dependencies are not satisfied', () => { + const { store } = createStore({ dependencyKey: 'currentPage' }) + expect(store.selectTestResourceIsPendingForFetch()).toBe(false) + }) + + test('triggers pending state as soon as dependency is resolved', async () => { + const { store } = createStore({ dependencyKey: 'currentPage' }) + store.doChangePaging({ currentPage: 1 }) + await tapReactors() + expect(store.selectTestResourceIsPendingForFetch()).toBe(true) + }) + + test('clears the store when dependency changes', async () => { + const { store, apiMock } = createStore({ dependencyKey: 'currentPage' }) + store.doChangePaging({ currentPage: 1 }) + await tapReactors() + store.doFetchTestResource() + await apiMock.resolveFetchRequest(1) + + store.doChangePaging({ currentPage: 2 }) + await tapReactors() + assertItem(store, { + data: undefined, + isLoading: false, + isPresent: false, + isPendingForFetch: true, + error: null, + errorPermanent: false, + isStale: false, + isReadyForRetry: false, + }) + }) + + test('stales a resource instead of clearing it with "stale" option', async () => { + const { store, apiMock } = createStore({ dependencyKey: { key: 'currentPage', staleOnChange: true } }) + store.doChangePaging({ currentPage: 1 }) + await tapReactors() + store.doFetchTestResource() + await apiMock.resolveFetchRequest(1) + + store.doChangePaging({ currentPage: 2 }) + await tapReactors() + + assertItem(store, { + data: 'One', + isLoading: false, + isPresent: true, + isPendingForFetch: true, + error: null, + errorPermanent: false, + isStale: true, + isReadyForRetry: false, + }) + }) + + test('allows to enable passing down blank values', async () => { + const { store } = createStore({ dependencyKey: { key: 'currentPage', allowBlank: true } }) + await tapReactors() + expect(store.selectTestResourceIsPendingForFetch()).toBe(true) + }) + + test.todo('mixes in dependency values into getPromise call') + }) + + describe('with multiple dependencies', () => { + test('does not try to fetch while dependencies are not satisfied', () => { + const { store } = createStore({ dependencyKey: ['currentPage', 'pageSize'] }) + expect(store.selectTestResourceIsPendingForFetch()).toBe(false) + }) + + test('triggers pending state as soon as dependency is resolved', async () => { + const { store } = createStore({ dependencyKey: ['currentPage', 'pageSize'] }) + store.doChangePaging({ currentPage: 1 }) + await tapReactors() + await tapReactors() + expect(store.selectTestResourceIsPendingForFetch()).toBe(true) + }) + + test('clears the store when dependency changes', async () => { + const { store, apiMock } = createStore({ dependencyKey: ['currentPage', 'pageSize'] }) + store.doChangePaging({ currentPage: 1 }) + await tapReactors() + await tapReactors() + + store.doFetchTestResource() + await apiMock.resolveFetchRequest(1) + + store.doChangePaging({ currentPage: 2 }) + await tapReactors() + assertItem(store, { + data: undefined, + isLoading: false, + isPresent: false, + isPendingForFetch: true, + error: null, + errorPermanent: false, + isStale: false, + isReadyForRetry: false, + }) + }) + + test('stales a resource instead of clearing it with "stale" option and allows blank items', async () => { + const { store } = createStore({ + dependencyKey: [{ key: 'currentPage', allowBlank: true }, { key: 'pageSize', staleOnChange: true }], + }) + + await tapReactors() + expect(store.selectTestResourceIsPendingForFetch()).toBe(true) + + store.doChangePaging({ pageSize: 120 }) + await tapReactors() + expect(store.selectTestResourceIsStale()).toBe(true) + }) + + test.todo('mixes in dependency values into getPromise call') + }) + }) }) function createStore(settings = {}, itemId = 1) { @@ -426,23 +546,53 @@ function createStore(settings = {}, itemId = 1) { ...settings, }) - const storeFactory = composeBundlesRaw(appTimeBundle, createReactorBundle(), apiMockBundle, asyncResourceBundle) + const pagingBundle = { + name: 'paging', + reducer: (state = { currentPage: null, pageSize: 10 }, action) => { + if (action.type === 'paging.change') { + return { + ...state, + ...action.payload, + } + } + return state + }, + doChangePaging: payload => ({ type: 'paging.change', payload: payload }), + selectCurrentPage: state => state.paging.currentPage, + selectPageSize: state => state.paging.pageSize, + } + + const storeFactory = composeBundlesRaw( + createReactorBundle(), + appTimeBundle, + apiMockBundle, + asyncResourceBundle, + pagingBundle + ) return { store: storeFactory(), apiMock } } function timeTravelTo(time, store) { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { try { timekeeper.travel(START_TIME + time) store.dispatch({ type: 'dummy action', payload: null }) // just tap the app time - setTimeout(resolve, 0) // reactors might need a tick to settle down + await tapReactors() + resolve() } catch (e) { reject(e) } }) } +async function tapReactors() { + const tapOneReactor = () => new Promise(resolve => setTimeout(resolve, 0)) + await tapOneReactor() + await tapOneReactor() + await tapOneReactor() +} + function assertItem( store, { data, isLoading, isStale, isReadyForRetry, isPresent, isPendingForFetch, error, errorPermanent } diff --git a/src/__tests__/makeAsyncResourceBundleKeys.test.js b/src/__tests__/makeAsyncResourceBundleKeys.test.js index 3bd1dc8..4610c34 100644 --- a/src/__tests__/makeAsyncResourceBundleKeys.test.js +++ b/src/__tests__/makeAsyncResourceBundleKeys.test.js @@ -1,17 +1,19 @@ import makeAsyncResourceBundleKeys from '../makeAsyncResourceBundleKeys' -describe('createAsyncResourcesBundle', () => { +describe('makeAsyncResourceBundleKeys', () => { test('creates correct object', () => { expect(makeAsyncResourceBundleKeys('myResource')).toEqual({ selectors: { raw: 'selectMyResourceRaw', data: 'selectMyResource', + dependencyValues: 'selectMyResourceDependencyValues', isLoading: 'selectMyResourceIsLoading', isPresent: 'selectMyResourceIsPresent', error: 'selectMyResourceError', isReadyForRetry: 'selectMyResourceIsReadyForRetry', retryAt: 'selectMyResourceRetryAt', errorIsPermanent: 'selectMyResourceErrorIsPermanent', + isDependencyResolved: 'selectMyResourceIsDependencyResolved', isStale: 'selectMyResourceIsStale', isPendingForFetch: 'selectMyResourceIsPendingForFetch', }, @@ -24,6 +26,7 @@ describe('createAsyncResourcesBundle', () => { isReadyForRetry: 'myResourceIsReadyForRetry', retryAt: 'myResourceRetryAt', errorIsPermanent: 'myResourceErrorIsPermanent', + isDependencyResolved: 'myResourceIsDependencyResolved', isStale: 'myResourceIsStale', isPendingForFetch: 'myResourceIsPendingForFetch', }, @@ -36,6 +39,7 @@ describe('createAsyncResourcesBundle', () => { reactors: { shouldExpire: 'reactMyResourceShouldExpire', shouldRetry: 'reactMyResourceShouldRetry', + shouldUpdateDependencyValues: 'reactMyResourceShouldUpdateDependencyValues', shouldBecomeStale: 'reactMyResourceShouldBecomeStale', }, }) diff --git a/src/__tests__/makeAsyncResourcesBundleKeys.test.js b/src/__tests__/makeAsyncResourcesBundleKeys.test.js index 178bedf..31385d4 100644 --- a/src/__tests__/makeAsyncResourcesBundleKeys.test.js +++ b/src/__tests__/makeAsyncResourcesBundleKeys.test.js @@ -1,6 +1,6 @@ import makeAsyncResourcesBundleKeys from '../makeAsyncResourcesBundleKeys' -describe('createAsyncResourcesBundle', () => { +describe('makeAsyncResourcesBundleKeys', () => { test('creates correct object', () => { expect(makeAsyncResourcesBundleKeys('myResources')).toEqual({ selectors: { diff --git a/src/common/keyToSelector.js b/src/common/keyToSelector.js new file mode 100644 index 0000000..25d54c6 --- /dev/null +++ b/src/common/keyToSelector.js @@ -0,0 +1,5 @@ +import nameToCapitalizedCase from './nameToCapitalizedCase' + +export default function keyToSelector(key) { + return `select${nameToCapitalizedCase(key)}` +} diff --git a/src/common/nameToCapitalizedCase.js b/src/common/nameToCapitalizedCase.js new file mode 100644 index 0000000..18a6422 --- /dev/null +++ b/src/common/nameToCapitalizedCase.js @@ -0,0 +1,3 @@ +export default function nameToCapitalizedCase(name) { + return name.charAt(0).toUpperCase() + name.slice(1) +} diff --git a/src/common/nameToUnderscoreCase.js b/src/common/nameToUnderscoreCase.js new file mode 100644 index 0000000..a30a1a3 --- /dev/null +++ b/src/common/nameToUnderscoreCase.js @@ -0,0 +1,6 @@ +export function nameToUnderscoreCase(name) { + return name + .replace(/\.?([A-Z]+)/g, (x, y) => '_' + y.toLowerCase()) + .replace(/^_/, '') + .toUpperCase() +} diff --git a/src/createAsyncResourceBundle.js b/src/createAsyncResourceBundle.js index dfed7fb..6a76fb3 100644 --- a/src/createAsyncResourceBundle.js +++ b/src/createAsyncResourceBundle.js @@ -1,6 +1,8 @@ import { createSelector } from 'redux-bundler' import makeAsyncResourceBundleKeys from './makeAsyncResourceBundleKeys' +import keyToSelector from './common/keyToSelector' +import { nameToUnderscoreCase } from './common/nameToUnderscoreCase' const Defaults = { name: undefined, // required @@ -10,6 +12,7 @@ const Defaults = { staleAfter: 900000, // fifteen minutes expireAfter: Infinity, persist: true, + dependencyKey: null, } const InitialState = { @@ -19,6 +22,8 @@ const InitialState = { dataAt: null, isStale: false, + dependencyValues: null, + error: null, errorAt: null, errorPermanent: false, @@ -26,15 +31,25 @@ const InitialState = { } export default function createAsyncResourceBundle(inputOptions) { - const { name, getPromise, actionBaseType, retryAfter, expireAfter, staleAfter, persist } = cookOptionsWithDefaults( - inputOptions - ) - - const baseType = actionBaseType || toUnderscoreCase(name) + const { + name, + getPromise, + actionBaseType, + retryAfter, + expireAfter, + staleAfter, + persist, + dependencyKeys, + stalingDependencyKeys, + blankingDependencyKeys, + } = cookOptionsWithDefaults(inputOptions) + + const baseType = actionBaseType || nameToUnderscoreCase(name) const expireEnabled = expireAfter && expireAfter !== Infinity const staleEnabled = staleAfter && staleAfter !== Infinity const retryEnabled = retryAfter && retryAfter !== Infinity + const dependenciesEnabled = Boolean(dependencyKeys) const { selectors, actionCreators, reactors } = makeAsyncResourceBundleKeys(name) @@ -47,6 +62,7 @@ export default function createAsyncResourceBundle(inputOptions) { EXPIRED: `${baseType}_EXPIRED`, READY_FOR_RETRY: `${baseType}_READY_FOR_RETRY`, ADJUSTED: `${baseType}_ADJUSTED`, + DEPENDENCIES_CHANGED: `${baseType}_DEPENDENCIES_CHANGED`, } const bundle = { @@ -126,6 +142,26 @@ export default function createAsyncResourceBundle(inputOptions) { } } + if (type === actions.DEPENDENCIES_CHANGED) { + const stale = + Boolean(state.dependencyValues) && + (stalingDependencyKeys.size > 0 && + changedKeys(state.dependencyValues, payload).every(key => stalingDependencyKeys.has(key))) + + if (stale) { + return { + ...state, + isStale: true, + dependencyValues: payload, + } + } else { + return { + ...InitialState, + dependencyValues: payload, + } + } + } + return state }, @@ -177,25 +213,38 @@ export default function createAsyncResourceBundle(inputOptions) { ), [selectors.isPendingForFetch]: createSelector( - selectors.raw, - ({ isLoading, errorAt, isReadyForRetry, isStale, dataAt }) => { - if (isLoading) { + selectors.error, + selectors.isPresent, + selectors.isStale, + selectors.isLoading, + selectors.isReadyForRetry, + selectors.isDependencyResolved, + (error, isPresent, isStale, isLoading, isReadyForRetry, isDependencyResolved) => { + if (!isDependencyResolved || isLoading) { return false } - if (errorAt) { + if (error) { return isReadyForRetry } - return isStale || !dataAt + return isStale || !isPresent } ), [actionCreators.doFetch]: () => thunkArgs => { - const { dispatch } = thunkArgs + const { dispatch, store } = thunkArgs dispatch({ type: actions.STARTED }) - return getPromise(thunkArgs).then( + let getPromiseArgs = thunkArgs + if (dependenciesEnabled) { + getPromiseArgs = { + ...getPromiseArgs, + ...store[selectors.dependencyValues](), + } + } + + return getPromise(getPromiseArgs).then( payload => { dispatch({ type: actions.FINISHED, payload }) }, @@ -251,12 +300,52 @@ export default function createAsyncResourceBundle(inputOptions) { ) } + if (dependenciesEnabled) { + bundle[selectors.isDependencyResolved] = createSelector( + selectors.dependencyValues, + dependencyValues => + Boolean(dependencyValues) && + dependencyKeys.every(key => { + const value = dependencyValues[key] + return blankingDependencyKeys.has(key) || (value !== null && value !== undefined) + }) + ) + + bundle[selectors.dependencyValues] = createSelector( + selectors.raw, + ({ dependencyValues }) => dependencyValues + ) + + bundle[reactors.shouldUpdateDependencyValues] = createSelector( + selectors.dependencyValues, + ...dependencyKeys.map(keyToSelector), + (dependencyValues, ...nextDependencyValuesList) => { + const dependenciesChanged = + !dependencyValues || + dependencyKeys.some((key, keyIndex) => dependencyValues[key] !== nextDependencyValuesList[keyIndex]) + + if (dependenciesChanged) { + const payload = nextDependencyValuesList.reduce( + (hash, value, index) => ({ + ...hash, + [dependencyKeys[index]]: value, + }), + {} + ) + return { type: actions.DEPENDENCIES_CHANGED, payload } + } + } + ) + } else { + bundle[selectors.isDependencyResolved] = () => true + } + return bundle } -function cookOptionsWithDefaults(options) { +function cookOptionsWithDefaults(inputOptions) { if (process.env.NODE_ENV !== 'production') { - const { name, getPromise } = options + const { name, getPromise } = inputOptions if (!name) { throw new Error('createAsyncResourceBundle: name parameter is required') @@ -267,12 +356,47 @@ function cookOptionsWithDefaults(options) { } } - return Object.assign({}, Defaults, options) + const { dependencyKey, ...options } = { ...Defaults, ...inputOptions } + + if (Array.isArray(dependencyKey) && dependencyKey.length) { + options.dependencyKeys = dependencyKey + } else if (dependencyKey) { + options.dependencyKeys = [dependencyKey] + } else { + delete options.dependencyKeys + } + + if (options.dependencyKeys) { + Object.assign( + options, + options.dependencyKeys.reduce( + (enhancements, option) => { + if (typeof option === 'string') { + enhancements.dependencyKeys.push(option) + } else { + const { key, staleOnChange, allowBlank } = option + if (staleOnChange) { + enhancements.stalingDependencyKeys.add(key) + } + if (allowBlank) { + enhancements.blankingDependencyKeys.add(key) + } + enhancements.dependencyKeys.push(key) + } + return enhancements + }, + { + dependencyKeys: [], + stalingDependencyKeys: new Set(), + blankingDependencyKeys: new Set(), + } + ) + ) + } + + return options } -function toUnderscoreCase(input) { - return input - .replace(/\.?([A-Z]+)/g, (x, y) => '_' + y.toLowerCase()) - .replace(/^_/, '') - .toUpperCase() +function changedKeys(left, right) { + return Object.keys(left).filter(key => left[key] !== right[key]) } diff --git a/src/makeAsyncResourceBundleKeys.js b/src/makeAsyncResourceBundleKeys.js index 5bf2a2b..51ecb44 100644 --- a/src/makeAsyncResourceBundleKeys.js +++ b/src/makeAsyncResourceBundleKeys.js @@ -1,10 +1,13 @@ +import nameToCapitalizedCase from './common/nameToCapitalizedCase' + export default function makeAsyncResourceBundleKeys(name) { - const upName = name.charAt(0).toUpperCase() + name.slice(1) + const upName = nameToCapitalizedCase(name) return { selectors: { raw: `select${upName}Raw`, data: `select${upName}`, + dependencyValues: `select${upName}DependencyValues`, isLoading: `select${upName}IsLoading`, isPresent: `select${upName}IsPresent`, error: `select${upName}Error`, @@ -13,6 +16,7 @@ export default function makeAsyncResourceBundleKeys(name) { errorIsPermanent: `select${upName}ErrorIsPermanent`, isStale: `select${upName}IsStale`, isPendingForFetch: `select${upName}IsPendingForFetch`, + isDependencyResolved: `select${upName}IsDependencyResolved`, }, keys: { raw: `${name}Raw`, @@ -25,6 +29,7 @@ export default function makeAsyncResourceBundleKeys(name) { errorIsPermanent: `${name}ErrorIsPermanent`, isStale: `${name}IsStale`, isPendingForFetch: `${name}IsPendingForFetch`, + isDependencyResolved: `${name}IsDependencyResolved`, }, actionCreators: { doFetch: `doFetch${upName}`, @@ -36,6 +41,7 @@ export default function makeAsyncResourceBundleKeys(name) { shouldExpire: `react${upName}ShouldExpire`, shouldRetry: `react${upName}ShouldRetry`, shouldBecomeStale: `react${upName}ShouldBecomeStale`, + shouldUpdateDependencyValues: `react${upName}ShouldUpdateDependencyValues`, }, } }