NGRX Angular服务-Getter使用createdSelector

时间:2018-10-24 06:58:50

标签: angular ngrx

我想提供一个可以获取ngrx选择器的服务。好的做法是直接在select中使用createSelector吗?

@Injectable()
export class LoginSelector{

    get data$() {
        return this.store.pipe(
            select(<b>createSelector</b>(
                this.loginState,
                function (state) {
                    return state && state.data;
                }
            ))
        );
    }

    constructor(
        protected storeActions$: Actions,
        protected store: Store<StoreState>,
    ) {}
}

可能不是因为createSelector总是重新运行新的MemoizedSelector

const selectData = <b>createSelector</b>(
  this.loginState,
  function (state) {
    return state && state.data;
  }
);

@Injectable()
export class LoginSelector{

  get data$() {
    return this.store.pipe(
      select(selectData)
    );
  }

  constructor(
    protected storeActions$: Actions,
    protected store: Store<StoreState>,
  ) {}
}

谢谢。

0 个答案:

没有答案