Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Entity): Change type for EntityState to interface #454

Merged
merged 2 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
test:
override:
- yarn run ci
- yarn run example:build:prod
- yarn run example:test -- --watch=false

deployment:
Expand Down
2 changes: 1 addition & 1 deletion modules/entity/src/entity_state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityState, EntityStateStr, EntityStateNum } from './models';
import { EntityState } from './models';

export function getInitialEntityState<V>(): EntityState<V> {
return {
Expand Down
19 changes: 5 additions & 14 deletions modules/entity/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ export type IdSelectorNum<T> = {

export type IdSelector<T> = IdSelectorStr<T> | IdSelectorNum<T>;

export type DictionaryStr<T> = {
[id: string]: T;
};

export type DictionaryNum<T> = {
[id: number]: T;
};

export type Dictionary<T> = DictionaryStr<T> | DictionaryNum<T>;
export abstract class Dictionary<T> implements DictionaryNum<T> {
[id: string]: T;
}

export type UpdateStr<T> = {
id: string;
Expand All @@ -40,18 +38,11 @@ export type UpdateNum<T> = {

export type Update<T> = UpdateStr<T> | UpdateNum<T>;

export interface EntityStateStr<T> {
ids: string[];
export interface EntityState<T> {
ids: any[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the possible values of ids are either string or number, it better to be explicit about that ids: string[] | number[];.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work with TypeScript

entities: Dictionary<T>;
}

export interface EntityStateNum<T> {
ids: number[];
entities: Dictionary<T>;
}

export type EntityState<T> = EntityStateStr<T> | EntityStateNum<T>;

export interface EntityDefinition<T> {
selectId: IdSelector<T>;
sortComparer: false | Comparer<T>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"example:start": "yarn run build && yarn run cli -- serve",
"example:start:aot": "yarn run build && yarn run cli -- serve --aot",
"example:test": "jest --watch",
"example:build:prod": "yarn build && yarn cli -- build --aot -prod --base-href \"/platform/example-app/\" --output-path \"./example-dist/example-app\"",
"example:build:prod": "yarn build && yarn cli -- build -prod --base-href \"/platform/example-app/\" --output-path \"./example-dist/example-app\"",
"ci": "yarn run build && yarn run test && nyc report --reporter=text-lcov | coveralls",
"prettier": "prettier --parser typescript --single-quote --trailing-comma es5 --write \"./**/*.ts\"",
"watch:tests": "chokidar 'modules/**/*.ts' --initial -c 'nyc --reporter=text --reporter=html yarn run test:unit'",
Expand Down