ngxs-labs / entity-state

⏱ WIP: Entity adapter
48 stars 12 forks source link

Allow numbers as keys #227

Open aWeinzierl opened 4 years ago

aWeinzierl commented 4 years ago

As dictionaries with numbers are a lot faster, and I could not think of any advantages, I use numbers as keys.

However, entity-state seems to allow only strings as keys. For instance, EntitySelector<T> is restricted to string-types (except when you use a custom lambda).

/**
 * An EntitySelector determines which entities will be affected.
 * Can be one of the following:
 * - a single ID in form of a string
 * - multiple IDs in form of an array of strings
 * - a predicate function that returns `true` for entities to be selected
 */
export declare type EntitySelector<T> = string | string[] | ((entity: T) => boolean);

It would be great if the restrictions could be just a little bit relaxed by extending such types to numbers.

JanMalch commented 4 years ago

I originally tried too type IDs as string | number, but ran into other issues and decided to leave it as string, since Object.keys would also only return strings. But it's worth looking into it again as some things have changed since. PRs are also welcome.

JanMalch commented 4 years ago

I started working on this in the issue-227 branch. I will have to see if the types will be consistent everywhere. For example the keys StateSelector cannot be anything else but string[]. So maybe a thing or two will be deprecated and/or replaced, but it looks promising.