Skip to content

Commit

Permalink
Removed a redundant function.
Browse files Browse the repository at this point in the history
  • Loading branch information
efreeti committed Sep 8, 2020
1 parent fa58f55 commit 2787e97
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
isLoadedResourceState,
isFailedResourceState,
getLastLoadedResourceState,
getLastLoadedResourceData,
getCurrentResourceError,
isOutdatedResourceState,
} from './async_resource_state';
Expand Down Expand Up @@ -181,42 +180,6 @@ describe('AsyncResourceState', () => {
});
});

describe('getLastLoadedResourceData()', () => {
it('returns undefined for UninitialisedResourceState', () => {
expect(getLastLoadedResourceData(uninitialisedResourceState)).toBeUndefined();
});

it('returns current data for LoadedResourceState', () => {
expect(getLastLoadedResourceData(loadedResourceState)).toStrictEqual(data);
});

it('returns undefined for initial FailedResourceState', () => {
expect(getLastLoadedResourceData(failedResourceStateInitially)).toBeUndefined();
});

it('returns last loaded data for subsequent FailedResourceState', () => {
expect(getLastLoadedResourceData(failedResourceStateSubsequently)).toStrictEqual(data);
});

it('returns undefined for initial LoadingResourceState', () => {
expect(getLastLoadedResourceData(loadingResourceStateInitially)).toBeUndefined();
});

it('returns previous data for LoadingResourceState after success', () => {
expect(getLastLoadedResourceData(loadingResourceStateAfterSuccess)).toStrictEqual(data);
});

it('returns undefined for LoadingResourceState after initial failure', () => {
expect(getLastLoadedResourceData(loadingResourceStateAfterInitialFailure)).toBeUndefined();
});

it('returns previous data for LoadingResourceState after subsequent failure', () => {
expect(getLastLoadedResourceData(loadingResourceStateAfterSubsequentFailure)).toStrictEqual(
data
);
});
});

describe('getCurrentResourceError()', () => {
it('returns undefined for UninitialisedResourceState', () => {
expect(getCurrentResourceError(uninitialisedResourceState)).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ export const getLastLoadedResourceState = <Data, Error>(
}
};

export const getLastLoadedResourceData = <Data, Error>(
state: Immutable<AsyncResourceState<Data, Error>>
): Immutable<Data> | undefined => {
return getLastLoadedResourceState(state)?.data;
};

export const getCurrentResourceError = <Data, Error>(
state: Immutable<AsyncResourceState<Data, Error>>
): Immutable<Error> | undefined => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Immutable, TrustedApp } from '../../../../../common/endpoint/types';
import {
AsyncResourceState,
getCurrentResourceError,
getLastLoadedResourceData,
getLastLoadedResourceState,
isLoadingResourceState,
isOutdatedResourceState,
Expand Down Expand Up @@ -49,7 +48,7 @@ export const getLastLoadedListResourceState = (
export const getListItems = (
state: Immutable<TrustedAppsListPageState>
): Immutable<TrustedApp[]> => {
return getLastLoadedResourceData(state.listView.currentListResourceState)?.items || [];
return getLastLoadedResourceState(state.listView.currentListResourceState)?.data.items || [];
};

export const getListCurrentPageIndex = (state: Immutable<TrustedAppsListPageState>): number => {
Expand All @@ -61,7 +60,9 @@ export const getListCurrentPageSize = (state: Immutable<TrustedAppsListPageState
};

export const getListTotalItemsCount = (state: Immutable<TrustedAppsListPageState>): number => {
return getLastLoadedResourceData(state.listView.currentListResourceState)?.totalItemsCount || 0;
return (
getLastLoadedResourceState(state.listView.currentListResourceState)?.data.totalItemsCount || 0
);
};

export const getListErrorMessage = (
Expand Down

0 comments on commit 2787e97

Please sign in to comment.