Skip to content

Commit

Permalink
introduce Predicate type
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Sep 14, 2018
1 parent 597c5c4 commit fa04889
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 5 additions & 4 deletions modules/entity/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export type UpdateNum<T> = {

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

export type Predicate<T> = {
(entity: T): boolean;
};

export interface EntityState<T> {
ids: string[] | number[];
entities: Dictionary<T>;
Expand All @@ -58,10 +62,7 @@ export interface EntityStateAdapter<T> {

removeMany<S extends EntityState<T>>(keys: string[], state: S): S;
removeMany<S extends EntityState<T>>(keys: number[], state: S): S;
removeMany<S extends EntityState<T>>(
predicate: (value: T) => boolean,
state: S
): S;
removeMany<S extends EntityState<T>>(predicate: Predicate<T>, state: S): S;

removeAll<S extends EntityState<T>>(state: S): S;

Expand Down
15 changes: 9 additions & 6 deletions modules/entity/src/unsorted_state_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { EntityState, EntityStateAdapter, IdSelector, Update } from './models';
import {
EntityState,
EntityStateAdapter,
IdSelector,
Update,
Predicate,
} from './models';
import { createStateOperator, DidMutate } from './state_adapter';
import { selectIdValue } from './utils';

Expand Down Expand Up @@ -49,12 +55,9 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
}

function removeManyMutably(keys: T[], state: R): DidMutate;
function removeManyMutably(predicate: Predicate<T>, state: R): DidMutate;
function removeManyMutably(
predicate: (value: T) => boolean,
state: R
): DidMutate;
function removeManyMutably(
keysOrPredicate: any[] | ((value: any) => boolean),
keysOrPredicate: any[] | Predicate<T>,
state: any
): DidMutate {
const keys =
Expand Down

0 comments on commit fa04889

Please sign in to comment.