Skip to content

Commit

Permalink
fix: 0 for expiryLength should not result in default (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 13, 2020
1 parent 121bb10 commit c75dca5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/rest-hooks/src/state/actionCreators.ts
Expand Up @@ -23,7 +23,11 @@ export function createReceive<
}: FetchAction<Payload, S>['meta'],
{ dataExpiryLength }: { dataExpiryLength: number },
): ReceiveAction<Payload, S> | RPCAction<Payload, S> | PurgeAction {
const expiryLength = options.dataExpiryLength || dataExpiryLength;
const expiryLength = options.dataExpiryLength ?? dataExpiryLength;
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
throw new Error('Negative dataExpiryLength are not allowed.');
}
const now = Date.now();
const meta:
| ReceiveAction['meta']
Expand Down Expand Up @@ -51,7 +55,11 @@ export function createReceiveError<S extends Schema = any>(
{ schema, url, responseType, options = {} }: FetchAction<any, S>['meta'],
{ errorExpiryLength }: { errorExpiryLength: number },
): ResponseActions {
const expiryLength = options.errorExpiryLength || errorExpiryLength;
const expiryLength = options.errorExpiryLength ?? errorExpiryLength;
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
throw new Error('Negative errorExpiryLength are not allowed.');
}
const now = Date.now();
return {
type: responseType as any,
Expand Down

0 comments on commit c75dca5

Please sign in to comment.