ngrx

How is it possible to debug or inspect the ngrx store, actions and effects?

人盡茶涼 提交于 2019-12-10 14:56:42
问题 I am having issues with my application not dispatching some actions or some effects not being called when an action is dispatched (see ngrx effect not being called when action is dispatched from component). I would like to know how to debug the ngrx store, actions and also effects. As the typescript sources for ngrx are not available on my environment (only the typings are available it seems), are there other ways to know what is going on in the store and effects? P.S. It seems the dev store

Ngrx: combine two selectors

随声附和 提交于 2019-12-10 13:56:30
问题 I've built this IStore : export interface IStore { user: IUser; sources: ISourceRedux; } where IUser is: export interface IUser { id: string; cname: string; sname: string; ... } and ISourceRedux is: export interface ISourceRedux { entities: { [key: string]: ISource }; ids: Array<string>; selectedIds: Array<string>; editingSource: ISource; defaultId: string; } So, I've created these selectors: export const getSourcesState = (state: IStore) => state.sources; export const getSelectedIds =

Angular rxjs Observable.timer is not a function with import

一曲冷凌霜 提交于 2019-12-10 12:54:14
问题 In my angular application I recieve the following error: ERROR TypeError: rxjs_Observable__WEBPACK_IMPORTED_MODULE_4__.Observable.timer is not a function at SwitchMapSubscriber.project (hybrid.effect.ts:20) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:34) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at FilterSubscriber.push../node_modules/rxjs/

How to dispatch an empty action?

坚强是说给别人听的谎言 提交于 2019-12-10 12:50:37
问题 I am using ngrx/effects. How can I dispatch an empty action? This is how I am doing now: @Effect() foo$ = this.actions$ .ofType(Actions.FOO) .withLatestFrom(this.store, (action, state) => ({ action, state })) .map(({ action, state }) => { if (state.foo.isCool) { return { type: Actions.BAR }; } else { return { type: 'NOT_EXIST' }; } }); Since I have to return an action, I am using return { type: 'NOT_EXIST' }; . Is there a better way to do this? 回答1: I've used similar unknown actions, but

return subject from inside map

99封情书 提交于 2019-12-10 12:24:42
问题 Asking this as a followup on this (How to return observable from subscribe), as the accepted solution didn't solve my use case Here is my code @Effect() searchQuery$ = this.actions$ .ofType(PlayerSearchActions.SEARCH_NEW_QUERY) .map(toPayload) .withLatestFrom(this.store) .map((latest: any[]) => latest[1]) .do((res)=>{console.log("Starting search with:",res);}) .switchMap((store: MyState) => this.youtubeSearch.resetPageToken() .searchAll(store.search.query, store.search.queryParams) .do((res)=

ngrx observable timer angular 5

蓝咒 提交于 2019-12-10 12:18:32
问题 I am very much a newbie to angular and ngrx. I am building a pomodoro timer app that integrates with the Todoist api. I have used the the [ngrx/platform example app as a starter app] (https://github.com/ngrx/example-app) which uses containers with components. I originally created a timer in pure rxjs that functions as it should on it's own. I am currently trying to integrate the timer into my code from a taskDetail page that works in conjunction with a selected-task page. There is a play

Is it possible to throw errors inside ngrx-effects without completing the Observable stream?

人盡茶涼 提交于 2019-12-10 10:56:07
问题 Is there any way to use throw with an Error object inside ngrx-effects streams without completing the stream? I've read these great answers on why the stream is being killed by throwing an error: @ngrx Effect does not run the second time ngrx effects error handling https://github.com/ngrx/platform/issues/646 My question is if I'm implementing the Angular ErrorHandler to catch errors, if I'm going to be able to use that with ngrx effects. @Effect() loginUserEffect: Observable<loginActions

Angular 2 : Thoughs about HMR and @ngrx/store

自闭症网瘾萝莉.ら 提交于 2019-12-10 10:08:04
问题 Before starting, this link can be useful : what is the purpose of HMR ?. I do not have a deep experience in huge projects management / conception. I'm still to young to have a beautiful beard. So I am here, looking for advices. the seed I am looking and thinking at this seed of angular 2 and I am wondering if using HMR is a viable option to develop a large application and how to do that. Those are just thoughs, I just want to discuss with you to make my decision. We all need to cross our

Angular 6 ngrx, how to add new item to array in state object?

心不动则不痛 提交于 2019-12-10 02:29:26
问题 I have a simple situation, I have actions Like CreatUser, CreateSuccess, CreateFail. How should I add new object to array and when Create action is dispatched or CreateSuccess ? And how should I do that? export function reducer(state = init, action: Actions): State { switch (action.type) { case ActionsTypes.CREATE: return { ...state, inProgress: true }; case ActionsTypes.CREATE_SUCCESS: return { ...state, users: state.users.push(action.payload), inProgress: false }; case ActionsTypes.CREATE

ngrx: how to pass parameters to selector inside createSelector method

落爺英雄遲暮 提交于 2019-12-09 14:47:40
问题 I have a very simple state in my store: const state = { records: [1,2,3], }; I have a selector for records: export const getRecords = createSelector(getState, (state: State) => state.records)); And what I want now is to have separate selectors for fetching each record by index. For this purpose I want to create one generic selector with props in this way: export const getRecordByIndex = createSelector( getRecords, (state: State, { index }) => state.records[index]), ); And after that create a