@wszerad/items 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/selector.ts DELETED
@@ -1,20 +0,0 @@
1
- import { Items } from './Items'
2
- import { StrOrNum } from './selectId'
3
-
4
- export type SelectorFn<E> = (entity: E) => boolean
5
- export type Selector<E, I> = Iterable<I> | SelectorFn<E>
6
- export type Operation<E, I> = (entity: E | undefined, id: I) => void
7
-
8
- export function selector<E, I extends StrOrNum>(items: Items<E, I>, selector: Selector<E, I>, operation: Operation<E, I>) {
9
- if (typeof selector === 'function') {
10
- items.getEntities().forEach((entity, id) => {
11
- if ((selector as SelectorFn<E>)(entity)) {
12
- operation(entity, id)
13
- }
14
- })
15
- } else {
16
- Array
17
- .from(selector as Iterable<I>)
18
- .forEach(id => operation(items.select(id), id))
19
- }
20
- }
package/src/updater.ts DELETED
@@ -1,6 +0,0 @@
1
- export type UpdateFn<E> = (entity: E) => E
2
- export type Updater<E> = UpdateFn<E> | Partial<E>
3
-
4
- export function update<E>(entity: E, updater: Updater<E>) {
5
- return { ...entity, ...(typeof updater === 'function' ? updater(entity) : updater) }
6
- }