55946: object-select store lists intermediate commit

This commit is contained in:
Kristof De Langhe
2018-11-15 14:13:16 +01:00
parent b11a168e72
commit 08063154e7
3 changed files with 84 additions and 47 deletions

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { createSelector, MemoizedSelector, Store } from '@ngrx/store';
import { ObjectSelectionsState, ObjectSelectionState } from './object-select.reducer';
import { ObjectSelectionListState, ObjectSelectionsState, ObjectSelectionState } from './object-select.reducer';
import {
ObjectSelectionDeselectAction,
ObjectSelectionInitialDeselectAction,
@@ -13,7 +13,8 @@ import { map } from 'rxjs/operators';
import { AppState } from '../../app.reducer';
const selectionStateSelector = (state: ObjectSelectionsState) => state.objectSelection;
const objectSelectionsStateSelector = (state: AppState) => state.objectSelection;
const objectSelectionsStateSelector = (state: ObjectSelectionListState) => state.objectSelection;
const objectSelectionListStateSelector = (state: AppState) => state.objectSelection;
/**
* Service that takes care of selecting and deselecting objects
@@ -28,11 +29,12 @@ export class ObjectSelectService {
}
/**
* Request the current selection of a given object
* Request the current selection of a given object in a given list
* @param {string} key The key of the list where the selection resides in
* @param {string} id The UUID of the object
* @returns {Observable<boolean>} Emits the current selection state of the given object, if it's unavailable, return false
*/
getSelected(id: string): Observable<boolean> {
getSelected(key: string, id: string): Observable<boolean> {
return this.store.select(selectionByIdSelector(id)).pipe(
map((object: ObjectSelectionState) => {
if (object) {
@@ -45,9 +47,8 @@ export class ObjectSelectService {
}
/**
* Request the current selection of a given object
* @param {string} id The UUID of the object
* @returns {Observable<boolean>} Emits the current selection state of the given object, if it's unavailable, return false
* Request the current selection of all objects
* @returns {Observable<boolean>} Emits the current selection state of all objects
*/
getAllSelected(): Observable<string[]> {
return this.appStore.select(objectSelectionsStateSelector).pipe(
@@ -56,50 +57,56 @@ export class ObjectSelectService {
}
/**
* Dispatches an initial select action to the store for a given object
* Dispatches an initial select action to the store for a given object in a given list
* @param {string} key The key of the list to select the object in
* @param {string} id The UUID of the object to select
*/
public initialSelect(id: string): void {
this.store.dispatch(new ObjectSelectionInitialSelectAction(id));
public initialSelect(key: string, id: string): void {
this.store.dispatch(new ObjectSelectionInitialSelectAction(key, id));
}
/**
* Dispatches an initial deselect action to the store for a given object
* Dispatches an initial deselect action to the store for a given object in a given list
* @param {string} key The key of the list to deselect the object in
* @param {string} id The UUID of the object to deselect
*/
public initialDeselect(id: string): void {
this.store.dispatch(new ObjectSelectionInitialDeselectAction(id));
public initialDeselect(key: string, id: string): void {
this.store.dispatch(new ObjectSelectionInitialDeselectAction(key, id));
}
/**
* Dispatches a select action to the store for a given object
* Dispatches a select action to the store for a given object in a given list
* @param {string} key The key of the list to select the object in
* @param {string} id The UUID of the object to select
*/
public select(id: string): void {
this.store.dispatch(new ObjectSelectionSelectAction(id));
public select(key: string, id: string): void {
this.store.dispatch(new ObjectSelectionSelectAction(key, id));
}
/**
* Dispatches a deselect action to the store for a given object
* Dispatches a deselect action to the store for a given object in a given list
* @param {string} key The key of the list to deselect the object in
* @param {string} id The UUID of the object to deselect
*/
public deselect(id: string): void {
this.store.dispatch(new ObjectSelectionDeselectAction(id));
public deselect(key: string, id: string): void {
this.store.dispatch(new ObjectSelectionDeselectAction(key, id));
}
/**
* Dispatches a switch action to the store for a given object
* Dispatches a switch action to the store for a given object in a given list
* @param {string} key The key of the list to select the object in
* @param {string} id The UUID of the object to select
*/
public switch(id: string): void {
this.store.dispatch(new ObjectSelectionSwitchAction(id));
public switch(key: string, id: string): void {
this.store.dispatch(new ObjectSelectionSwitchAction(key, id));
}
/**
* Dispatches a reset action to the store for all objects
* Dispatches a reset action to the store for all objects (in a list)
* @param {string} key The key of the list to clear all selections for
*/
public reset(): void {
this.store.dispatch(new ObjectSelectionResetAction(null));
public reset(key?: string): void {
this.store.dispatch(new ObjectSelectionResetAction(key, null));
}
}