Skip to content

Commit

Permalink
fix: make arrays readonly (#154)
Browse files Browse the repository at this point in the history
* fix: make arrays readonly

* fix: make arrays readonly
  • Loading branch information
dankreiger committed Apr 11, 2024
1 parent 415e4a6 commit a47054a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.19.0
20.11.1
35 changes: 20 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"src"
],
"scripts": {
"build": "scripty",
"build": "npm run clean && npx tsc && npx rollup -c",
"clean": "scripty",
"commit": "scripty",
"commit:protect": "scripty",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

npm run clean
echo "┏━━━ 📦 build ━━━━━━━━━━━━━━━━━━━"
tsc && rollup -c
npx tsc && npx rollup -c
5 changes: 5 additions & 0 deletions src/typings/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export type ObjectKey = string | number | symbol;

export type EntityDict<Entity, Key extends ObjectKey> = {
entities: Record<Key, ReadonlyArray<Entity> | undefined>;
ids: ReadonlyArray<Key>;
};

export type MutableEntityDict<Entity, Key extends ObjectKey> = {
entities: Record<Key, Entity[] | undefined>;
ids: Key[];
};
4 changes: 2 additions & 2 deletions src/utils/__internal__/groupBy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EntityDict } from '../../typings';
import type { MutableEntityDict } from '../../typings';

/**
* O(n) implementation of groupBy
Expand All @@ -7,7 +7,7 @@ export const groupBy = <K extends keyof T, T extends Record<K, T[K]>>(
key: K,
items: T[]
) => {
const result = { entities: {}, ids: [] } as EntityDict<T, T[K]>;
const result = { entities: {}, ids: [] } as MutableEntityDict<T, T[K]>;

for (let i = 0; i < items.length; i++) {
if (result.entities[items[i][key]]) {
Expand Down

0 comments on commit a47054a

Please sign in to comment.