-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
57 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
libs/core/state/src/operation/entity/helpers/create-fake-id.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
libs/core/state/src/operation/entity/helpers/create-fake-id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters