UNPKG

@snipsonian/observable-state

Version:

Observable-state snippets (redux-like)

46 lines (45 loc) 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasAsyncOperationFailed = exports.hasAsyncOperationSucceeded = exports.hasFetchFailed = exports.hasFetchSucceeded = exports.isAsyncOperationBusy = exports.isUpdateBusy = exports.isFetchBusy = exports.isAnyAsyncOperationBusy = exports.isValidAsyncOperation = exports.asyncOperationList = void 0; const types_1 = require("./types"); exports.asyncOperationList = Object.values(types_1.AsyncOperation); function isValidAsyncOperation(possibleOperation) { return exports.asyncOperationList.indexOf(possibleOperation) !== -1; } exports.isValidAsyncOperation = isValidAsyncOperation; function isAnyAsyncOperationBusy(asyncEntity) { return Object.values(types_1.AsyncOperation) .some((operation) => isAsyncOperationBusy(asyncEntity, operation)); } exports.isAnyAsyncOperationBusy = isAnyAsyncOperationBusy; function isFetchBusy(asyncEntity) { return isAsyncOperationBusy(asyncEntity, types_1.AsyncOperation.fetch); } exports.isFetchBusy = isFetchBusy; function isUpdateBusy(asyncEntity) { return isAsyncOperationBusy(asyncEntity, types_1.AsyncOperation.update); } exports.isUpdateBusy = isUpdateBusy; function isAsyncOperationBusy(asyncEntity, operation) { return hasAsyncOperationExpectedStatus(asyncEntity, operation, types_1.AsyncStatus.Busy); } exports.isAsyncOperationBusy = isAsyncOperationBusy; function hasFetchSucceeded(asyncEntity) { return hasAsyncOperationSucceeded(asyncEntity, types_1.AsyncOperation.fetch); } exports.hasFetchSucceeded = hasFetchSucceeded; function hasFetchFailed(asyncEntity) { return hasAsyncOperationFailed(asyncEntity, types_1.AsyncOperation.fetch); } exports.hasFetchFailed = hasFetchFailed; function hasAsyncOperationSucceeded(asyncEntity, operation) { return hasAsyncOperationExpectedStatus(asyncEntity, operation, types_1.AsyncStatus.Success); } exports.hasAsyncOperationSucceeded = hasAsyncOperationSucceeded; function hasAsyncOperationFailed(asyncEntity, operation) { return hasAsyncOperationExpectedStatus(asyncEntity, operation, types_1.AsyncStatus.Error); } exports.hasAsyncOperationFailed = hasAsyncOperationFailed; function hasAsyncOperationExpectedStatus(asyncEntity, operation, status) { return asyncEntity[operation] && (asyncEntity[operation].status === status); }