Skip to content

Commit

Permalink
fix(core): selectLoading returns true for not loading state (#2798)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed May 14, 2024
1 parent 0c1edcc commit c7f164e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 49 deletions.
21 changes: 0 additions & 21 deletions libs/core/state/src/operation/entity/helpers.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { daffOperationEntityCreateFakeId } from './create-fake-id';

describe('@daffodil/core/state | daffOperationEntityCreateFakeId', () => {
let result: string;

beforeEach(() => {
result = daffOperationEntityCreateFakeId('test');
});

it('should return a string containing a greek lowercase sigma', () => {
expect(result).toContain('ε');
});

it('should return a string containing the passed key', () => {
expect(result).toContain('test');
});

it('should return distinct strings when called in quick succession', () => {
expect(result).not.toEqual(daffOperationEntityCreateFakeId());
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Generate a fake ID for use with placeholder entities.
*
* @param key An optional key that can augment the randomly generated ID.
* @returns A string cont
*/
export function daffOperationEntityCreateFakeId(key: string = ''): string {
return `ε-${Date.now()}-${key}`;
}
2 changes: 1 addition & 1 deletion libs/core/state/src/operation/entity/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './adapter';
export * from './selectors';
export * from './helpers';
export * from './helpers/create-fake-id';
export { DaffOperationEntity } from './type';
export { DaffOperationEntityState } from './state.type';
10 changes: 7 additions & 3 deletions libs/core/state/src/operation/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
} from '@ngrx/store';

import { DaffOperationState } from './state';
import { DaffState } from '../states/public_api';
import {
DaffState,
daffStateIsLoading,
daffStateIsMutating,
} from '../states/public_api';

/**
* Selectors for an operation state.
Expand Down Expand Up @@ -58,15 +62,15 @@ export function daffOperationStateSelectorFactory <
);
const selectLoading = createSelector(
selectLoadingState,
loadingState => loadingState !== DaffState.Stable,
loadingState => daffStateIsLoading(loadingState),
);
const selectResolving = createSelector(
selectLoadingState,
loadingState => loadingState === DaffState.Resolving,
);
const selectMutating = createSelector(
selectLoadingState,
loadingState => loadingState === DaffState.Mutating,
loadingState => daffStateIsMutating(loadingState),
);
const selectErrors = createSelector(
selectState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { DaffState } from '@daffodil/core/state';

import {
daffOperationEntityCreateFakeId,
daffStateIsLoading,
} from './helpers';
import { daffStateIsLoading } from './helpers';

describe('@daffodil/core/state | daffStateIsLoading', () => {
let result: boolean;
Expand Down Expand Up @@ -78,23 +75,3 @@ describe('@daffodil/core/state | daffStateIsLoading', () => {
});
});
});

describe('@daffodil/core/state | daffOperationEntityCreateFakeId', () => {
let result: string;

beforeEach(() => {
result = daffOperationEntityCreateFakeId('test');
});

it('should return a string containing a greek lowercase sigma', () => {
expect(result).toContain('ε');
});

it('should return a string containing the passed key', () => {
expect(result).toContain('test');
});

it('should return distinct strings when called in quick succession', () => {
expect(result).not.toEqual(daffOperationEntityCreateFakeId());
});
});
17 changes: 17 additions & 0 deletions libs/core/state/src/states/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DaffState } from './state.enum';

/**
* Returns whether the state is one that represents an operation in progress.
*/
export function daffStateIsLoading(daffState: DaffState): boolean {
return daffStateIsMutating(daffState) || daffState === DaffState.Resolving;
}

/**
* Returns whether the state is one that represents a mutable operation in progress.
*/
export function daffStateIsMutating(daffState: DaffState): boolean {
return daffState === DaffState.Adding
|| daffState === DaffState.Updating
|| daffState === DaffState.Deleting;
}
1 change: 1 addition & 0 deletions libs/core/state/src/states/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { DaffState } from './state.enum';
export { DaffMutableLoadingState } from './mutable-loading';
export { DaffLoadingState } from './loading';
export { DaffStateable } from './stateable.interface';
export * from './helpers';

0 comments on commit c7f164e

Please sign in to comment.