react-waitables
Advanced tools
Comparing version 1.11.2 to 2.0.0
@@ -158,5 +158,5 @@ "use strict"; | ||
}); | ||
return (0, use_waitable_1.useWaitable)(evaluate, Object.assign(Object.assign({ defaultValue: 'use-primary-function' }, args), { hardResetBindings: (0, array_like_1.concatArrays)((_a = (0, array_like_1.normalizeAsOptionalArray)(args.hardResetBindings)) !== null && _a !== void 0 ? _a : emptyHardResetBindings, stableWaitableIsCompletes, stableAllBindings), lockedWhile: (0, array_like_1.concatArrays)((_b = (0, array_like_1.normalizeAsOptionalArray)(args.lockedWhile)) !== null && _b !== void 0 ? _b : emptyLockedWhile, stableWaitableIsLockedWithoutValueBindings) })); | ||
return (0, use_waitable_1.useWaitable)(evaluate, Object.assign(Object.assign({ defaultValue: 'use-primary-function-if-unlocked' }, args), { hardResetBindings: (0, array_like_1.concatArrays)((_a = (0, array_like_1.normalizeAsOptionalArray)(args.hardResetBindings)) !== null && _a !== void 0 ? _a : emptyHardResetBindings, stableWaitableIsCompletes, stableAllBindings), lockedWhile: (0, array_like_1.concatArrays)((_b = (0, array_like_1.normalizeAsOptionalArray)(args.lockedWhile)) !== null && _b !== void 0 ? _b : emptyLockedWhile, stableWaitableIsLockedWithoutValueBindings) })); | ||
}; | ||
exports.useDerivedWaitable = useDerivedWaitable; | ||
//# sourceMappingURL=use-derived-waitable.js.map |
@@ -31,4 +31,5 @@ "use strict"; | ||
* | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'`, | ||
* `reset('soft')` is automatically called so the primary function can be run again as applicable. | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'` or | ||
* `defaultValue='use-primary-function-if-unlocked'`, `reset('soft')` is automatically called so the primary function can be run again as | ||
* applicable. | ||
*/ | ||
@@ -118,2 +119,19 @@ const useWaitable = (primaryFunc, args) => { | ||
} | ||
else if (defaultValue === 'use-primary-function-if-unlocked') { | ||
if (!isLocked.get()) { | ||
return (0, update_waitable_bindings_with_primary_function_for_default_value_1.updateWaitableBindingsWithPrimaryFunctionForDefaultValue)({ | ||
primaryFunc, | ||
isBusy, | ||
error, | ||
value, | ||
alreadyRanFunc, | ||
resetCount, | ||
softReset, | ||
onSuccess | ||
}); | ||
} | ||
else { | ||
return (0, update_waitable_bindings_with_default_value_producer_1.updateWaitableBindingsWithDefaultValueProducer)({ areValuesEqual, defaultValue: undefined, error, value }); | ||
} | ||
} | ||
else { | ||
@@ -120,0 +138,0 @@ return (0, update_waitable_bindings_with_default_value_producer_1.updateWaitableBindingsWithDefaultValueProducer)({ areValuesEqual, defaultValue, error, value }); |
@@ -155,4 +155,4 @@ import { useMemo } from 'react'; | ||
}); | ||
return useWaitable(evaluate, Object.assign(Object.assign({ defaultValue: 'use-primary-function' }, args), { hardResetBindings: concatArrays((_a = normalizeAsOptionalArray(args.hardResetBindings)) !== null && _a !== void 0 ? _a : emptyHardResetBindings, stableWaitableIsCompletes, stableAllBindings), lockedWhile: concatArrays((_b = normalizeAsOptionalArray(args.lockedWhile)) !== null && _b !== void 0 ? _b : emptyLockedWhile, stableWaitableIsLockedWithoutValueBindings) })); | ||
return useWaitable(evaluate, Object.assign(Object.assign({ defaultValue: 'use-primary-function-if-unlocked' }, args), { hardResetBindings: concatArrays((_a = normalizeAsOptionalArray(args.hardResetBindings)) !== null && _a !== void 0 ? _a : emptyHardResetBindings, stableWaitableIsCompletes, stableAllBindings), lockedWhile: concatArrays((_b = normalizeAsOptionalArray(args.lockedWhile)) !== null && _b !== void 0 ? _b : emptyLockedWhile, stableWaitableIsLockedWithoutValueBindings) })); | ||
}; | ||
//# sourceMappingURL=use-derived-waitable.js.map |
@@ -28,4 +28,5 @@ import { useMemo, useRef } from 'react'; | ||
* | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'`, | ||
* `reset('soft')` is automatically called so the primary function can be run again as applicable. | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'` or | ||
* `defaultValue='use-primary-function-if-unlocked'`, `reset('soft')` is automatically called so the primary function can be run again as | ||
* applicable. | ||
*/ | ||
@@ -115,2 +116,19 @@ export const useWaitable = (primaryFunc, args) => { | ||
} | ||
else if (defaultValue === 'use-primary-function-if-unlocked') { | ||
if (!isLocked.get()) { | ||
return updateWaitableBindingsWithPrimaryFunctionForDefaultValue({ | ||
primaryFunc, | ||
isBusy, | ||
error, | ||
value, | ||
alreadyRanFunc, | ||
resetCount, | ||
softReset, | ||
onSuccess | ||
}); | ||
} | ||
else { | ||
return updateWaitableBindingsWithDefaultValueProducer({ areValuesEqual, defaultValue: undefined, error, value }); | ||
} | ||
} | ||
else { | ||
@@ -117,0 +135,0 @@ return updateWaitableBindingsWithDefaultValueProducer({ areValuesEqual, defaultValue, error, value }); |
@@ -65,6 +65,6 @@ import type { DependencyList } from 'react'; | ||
* This can be used to generate a default value, which will be used to initialize the value and whenever this waitable is hard reset. You | ||
* may alternatively, specify `'use-primary-function'`, in which case the primary function will be called immediately on initialization or | ||
* reset. | ||
* may alternatively, specify `'use-primary-function'` or `'use-primary-function-if-unlocked'`, in which case the primary function will be | ||
* called immediately on initialization or reset. | ||
*/ | ||
defaultValue?: UseWaitableDefaultValueProducer<SuccessT> | 'use-primary-function'; | ||
defaultValue?: UseWaitableDefaultValueProducer<SuccessT> | 'use-primary-function' | 'use-primary-function-if-unlocked'; | ||
/** | ||
@@ -71,0 +71,0 @@ * Called each time `setFailure` is called (except if the call to `setFailure` is ignored, ex. due to a reset or when an error occurs when |
@@ -18,6 +18,7 @@ import type { EmptyObject } from 'react-bindings'; | ||
* | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'`, | ||
* `reset('soft')` is automatically called so the primary function can be run again as applicable. | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'` or | ||
* `defaultValue='use-primary-function-if-unlocked'`, `reset('soft')` is automatically called so the primary function can be run again as | ||
* applicable. | ||
*/ | ||
export declare const useWaitable: <SuccessT, FailureT = any, ExtraFieldsT extends object = EmptyObject>(primaryFunc: WaitablePrimaryFunction<SuccessT, FailureT>, args: UseWaitableArgs<SuccessT, FailureT, ExtraFieldsT>) => Waitable<SuccessT, FailureT> & ExtraFieldsT; | ||
//# sourceMappingURL=use-waitable.d.ts.map |
{ | ||
"name": "react-waitables", | ||
"version": "1.11.2", | ||
"version": "2.0.0", | ||
"description": "Async data bindings for React", | ||
@@ -44,17 +44,17 @@ "keywords": [ | ||
"devDependencies": { | ||
"@testing-library/react": "^14.0.0", | ||
"@types/jest": "^29.5.5", | ||
"@types/react": "18.2.28", | ||
"@types/react-dom": "18.2.13", | ||
"@typescript-eslint/eslint-plugin": "^6.7.5", | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"eslint": "8.51.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"@testing-library/react": "^14.2.1", | ||
"@types/jest": "^29.5.12", | ||
"@types/react": "18.2.58", | ||
"@types/react-dom": "18.2.19", | ||
"@typescript-eslint/eslint-plugin": "^7.0.2", | ||
"@typescript-eslint/parser": "^7.0.2", | ||
"eslint": "8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-simple-import-sort": "^12.0.0", | ||
"eslint-plugin-tsdoc": "^0.2.17", | ||
@@ -64,10 +64,10 @@ "jest": "29.7.0", | ||
"madge": "6.1.0", | ||
"prettier": "3.0.3", | ||
"prettier": "3.2.5", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"trash-cli": "5.0.0", | ||
"ts-jest": "^29.1.1", | ||
"typedoc": "^0.25.2", | ||
"typescript": "5.2.2" | ||
"ts-jest": "^29.1.2", | ||
"typedoc": "^0.25.8", | ||
"typescript": "5.3.3" | ||
} | ||
} |
@@ -214,3 +214,3 @@ import { useMemo } from 'react'; | ||
return useWaitable<SuccessT, FailureT, ExtraFieldsT>(evaluate, { | ||
defaultValue: 'use-primary-function', | ||
defaultValue: 'use-primary-function-if-unlocked', | ||
...args, | ||
@@ -217,0 +217,0 @@ hardResetBindings: concatArrays( |
@@ -78,6 +78,6 @@ import type { DependencyList } from 'react'; | ||
* This can be used to generate a default value, which will be used to initialize the value and whenever this waitable is hard reset. You | ||
* may alternatively, specify `'use-primary-function'`, in which case the primary function will be called immediately on initialization or | ||
* reset. | ||
* may alternatively, specify `'use-primary-function'` or `'use-primary-function-if-unlocked'`, in which case the primary function will be | ||
* called immediately on initialization or reset. | ||
*/ | ||
defaultValue?: UseWaitableDefaultValueProducer<SuccessT> | 'use-primary-function'; | ||
defaultValue?: UseWaitableDefaultValueProducer<SuccessT> | 'use-primary-function' | 'use-primary-function-if-unlocked'; | ||
@@ -84,0 +84,0 @@ /** |
@@ -46,4 +46,5 @@ import { useMemo, useRef } from 'react'; | ||
* | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'`, | ||
* `reset('soft')` is automatically called so the primary function can be run again as applicable. | ||
* During default value generation, if an error occurs, either thrown or via `setFailure` if using `defaultValue='use-primary-function'` or | ||
* `defaultValue='use-primary-function-if-unlocked'`, `reset('soft')` is automatically called so the primary function can be run again as | ||
* applicable. | ||
*/ | ||
@@ -166,2 +167,17 @@ export const useWaitable = <SuccessT, FailureT = any, ExtraFieldsT extends object = EmptyObject>( | ||
}); | ||
} else if (defaultValue === 'use-primary-function-if-unlocked') { | ||
if (!isLocked.get()) { | ||
return updateWaitableBindingsWithPrimaryFunctionForDefaultValue({ | ||
primaryFunc, | ||
isBusy, | ||
error, | ||
value, | ||
alreadyRanFunc, | ||
resetCount, | ||
softReset, | ||
onSuccess | ||
}); | ||
} else { | ||
return updateWaitableBindingsWithDefaultValueProducer({ areValuesEqual, defaultValue: undefined, error, value }); | ||
} | ||
} else { | ||
@@ -168,0 +184,0 @@ return updateWaitableBindingsWithDefaultValueProducer({ areValuesEqual, defaultValue, error, value }); |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import type { InferBindingGetType, ReadonlyBinding } from 'react-bindings'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import type { InferBindingGetType, ReadonlyBinding } from 'react-bindings'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import type { InferBindingGetType, ReadonlyBinding } from 'react-bindings'; | ||
@@ -2,0 +3,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
475956
7408