-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strategy): move strategies from feature to entity store and add …
…filter selection strategy (#500) * feat(entity table): connect entity tables to the state view * style(*): remove now useless entity watcher * feat(entity selector): fix issue with empty value * wip(strategy): move strategies from feature to entity store and add filter selection strategy * lint(*)
- Loading branch information
Showing
13 changed files
with
216 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/common/src/lib/entity/shared/strategies/filter-selection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { EntityRecord } from '../entity.interfaces'; | ||
import { EntityStore } from '../store'; | ||
import { EntityStoreStrategy } from './strategy'; | ||
|
||
/** | ||
* When active, this strategy filters a store's stateView to return | ||
* selected entities only. | ||
*/ | ||
export class EntityStoreFilterSelectionStrategy extends EntityStoreStrategy { | ||
|
||
/** | ||
* Store / filter ids map | ||
*/ | ||
private filters: Map<EntityStore, string> = new Map(); | ||
|
||
/** | ||
* Bind this strategy to a store and start filtering it | ||
* @param store Entity store | ||
*/ | ||
bindStore(store: EntityStore) { | ||
super.bindStore(store); | ||
if (this.active === true) { | ||
this.filterStore(store); | ||
} | ||
} | ||
|
||
/** | ||
* Unbind this strategy from a store and stop filtering it | ||
* @param store Entity store | ||
*/ | ||
unbindStore(store: EntityStore) { | ||
super.unbindStore(store); | ||
if (this.active === true) { | ||
this.unfilterStore(store); | ||
} | ||
} | ||
|
||
/** | ||
* Start filtering all stores | ||
* @internal | ||
*/ | ||
protected doActivate() { | ||
this.filterAll(); | ||
} | ||
|
||
/** | ||
* Stop filtering all stores | ||
* @internal | ||
*/ | ||
protected doDeactivate() { | ||
this.unfilterAll(); | ||
} | ||
|
||
/** | ||
* Filter all stores | ||
*/ | ||
private filterAll() { | ||
this.stores.forEach((store: EntityStore) => this.filterStore(store)); | ||
} | ||
|
||
/** | ||
* Unfilter all stores | ||
*/ | ||
private unfilterAll() { | ||
this.stores.forEach((store: EntityStore) => this.unfilterStore(store)); | ||
} | ||
|
||
/** | ||
* Filter a store and add it to the filters map | ||
*/ | ||
private filterStore(store: EntityStore) { | ||
if (this.filters.has(store)) { | ||
return; | ||
} | ||
|
||
const filter = (record: EntityRecord<object>) => { | ||
return record.state.selected === true; | ||
}; | ||
this.filters.set(store, store.stateView.addFilter(filter)); | ||
} | ||
|
||
/** | ||
* Unfilter a store and delete it from the filters map | ||
*/ | ||
private unfilterStore(store: EntityStore) { | ||
const filterId = this.filters.get(store); | ||
if (filterId === undefined) { | ||
return; | ||
} | ||
|
||
store.stateView.removeFilter(filterId); | ||
this.filters.delete(store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './strategy'; | ||
export * from './filter-selection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.