-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
defaultMaxAge
to entity operator
* Introduce to `defaultMaxAge` to IEntityOptions + Add EntityAge with predefined common ages for use with `defaultMaxAge` * Update @entity decorator to support passing name in only or options or both > Move key decorator tokens into entity-tokens.ts > Extract entity decorator into its own file entity-decorator.ts > Extract key decorator into its own file key-decorator.ts * Update index/public api to reference all exports from new locations * Added EntityAge enum to public api * Removed all imports from '../..' Issues #144 #141
- Loading branch information
Jon Rista
committed
Aug 30, 2020
1 parent
d106ce4
commit 8e4f61b
Showing
40 changed files
with
210 additions
and
205 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
projects/ngrx-auto-entity/src/lib/actions/delete-by-key-actions.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
2 changes: 1 addition & 1 deletion
2
projects/ngrx-auto-entity/src/lib/actions/deselection-actions.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
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
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
39 changes: 39 additions & 0 deletions
39
projects/ngrx-auto-entity/src/lib/decorators/entity-decorator.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,39 @@ | ||
import { IEntityOptions } from './entity-options'; | ||
import { ENTITY_OPTS_PROP } from './entity-tokens'; | ||
|
||
/** | ||
* Entity decorator for configuring each entity model. | ||
* | ||
* @param options - The configuration options to apply | ||
*/ | ||
export function Entity(options: IEntityOptions); | ||
|
||
/** | ||
* Entity decorator for configuring each entity model. | ||
* | ||
* @param modelName - The model name option to apply | ||
* @param options - Additional configuration options to apply | ||
*/ | ||
export function Entity(modelName?: string, options?: IEntityOptions); | ||
|
||
/** | ||
* Entity decorator for configuring each entity model. | ||
* | ||
* @param nameOrOptions - The model name or configuration options to apply | ||
* @param maybeOptions - Additional options to apply if a model name is passed as the first param | ||
*/ | ||
export function Entity(nameOrOptions: string | IEntityOptions, maybeOptions?: IEntityOptions) { | ||
return function entityDecorator(constructor: any) { | ||
const initialOptions = typeof nameOrOptions === 'object' ? nameOrOptions : { modelName: nameOrOptions }; | ||
const options = maybeOptions ? { ...maybeOptions, ...initialOptions } : initialOptions; | ||
|
||
const descriptor = Object.create(null); | ||
descriptor.configurable = false; | ||
descriptor.enumerable = false; | ||
descriptor.writable = false; | ||
descriptor.value = options; | ||
Object.defineProperty(constructor, ENTITY_OPTS_PROP, descriptor); | ||
|
||
return constructor; | ||
}; | ||
} |
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
6 changes: 6 additions & 0 deletions
6
projects/ngrx-auto-entity/src/lib/decorators/entity-tokens.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 |
---|---|---|
@@ -1 +1,7 @@ | ||
// NOTE: The following constants should be Symbol() to avoid any potential conflict with | ||
// any user-defined properties on the entity models. However, use of Symbol() here causes | ||
// problems with the Jest test runner at the current time | ||
|
||
export const ENTITY_OPTS_PROP = '__nae_entity_opts'; | ||
export const NAE_KEYS = '__nae_keys'; | ||
export const NAE_KEY_NAMES = '__nae_key_names'; |
4 changes: 2 additions & 2 deletions
4
projects/ngrx-auto-entity/src/lib/decorators/entity-util.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
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
12 changes: 12 additions & 0 deletions
12
projects/ngrx-auto-entity/src/lib/decorators/key-decorator.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,12 @@ | ||
import { NAE_KEY_NAMES, NAE_KEYS } from './entity-tokens'; | ||
|
||
/** | ||
* Used to designate the key property for the entity | ||
* | ||
* @param target the entity's class | ||
* @param keyName the key's name | ||
*/ | ||
export function Key(target, keyName: string | symbol): void { | ||
target[NAE_KEY_NAMES] = target[NAE_KEY_NAMES] ? [...target[NAE_KEY_NAMES], keyName] : [keyName]; | ||
Object.defineProperty(target, NAE_KEYS, { get: () => target[NAE_KEY_NAMES] }); | ||
} |
20 changes: 2 additions & 18 deletions
20
...grx-auto-entity/src/lib/decorators/key.ts → ...uto-entity/src/lib/decorators/key-util.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
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
Oops, something went wrong.