import {
  createSelector,
  MemoizedSelector,
} from '@ngrx/store';

export class StateSelector<State> {
  public constructor(private _selector: MemoizedSelector<object, State>) {
  }

  public select = (propertyPath: string) => createSelector(this._selector, (state: State) => {
    return propertyPath.split('.').reduce(
      (prev, curr) => {
        return prev ? prev[curr] : undefined;
      }, state);
  })
}
