ngrx

Angular 5 Ngrx State lost during browser page refresh

穿精又带淫゛_ 提交于 2019-11-28 09:38:28
问题 I am new to angular 5 and Ngrx, some how i managed to implement a login functionality, once login is success i am taking the user to dashboard. But if I refresh the page the user state seems to be lost. How to make the user state persistent even the page reloads ? 回答1: How to make the user state persistent even the page reloads? as @user184994 Mentioned NGRX state is only held in memory. If you want it to persist between page refreshes Go for LocalStorage or sessionStorage localStorage and

Getting current state in ngrx

我们两清 提交于 2019-11-28 06:52:45
问题 Here is the solution for getting the current state in ngrx. The example is simple - you just use take(1) . But in rxjs documentation for take it says: Returns a specified number of contiguous elements from the start of an observable sequence How come taking the first value gets the current state (i.e. the last value)? Also I'm having trouble mocking this behavior in unit tests using Subject . 回答1: The ngrx-store is a ReplaySubject of length=1 , this means only 1(the latest) value is cached

How to get current value of State object with @ngrx/store?

笑着哭i 提交于 2019-11-28 05:17:12
My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I'm doing it like this: constructor ( public _store: Store<AppState>, public _APIService:APIService) { const store$ = this._store.select ('StateReducer'); .../... let update = this.actions$.filter ( action => action.type==UPDATE ) .do( (action) => this._store.dispatch({type: REDUCER_UPDATING, payload : action.payload }) ) *** GET STATE ***==> .mergeMap ( action => store$.map ( (state : AppState)=> state.dataForUpdate ).distinctUntilChanged(), (action, dataForUpdate) { return {

how to subscribe to action success callback using ngrx and effects

笑着哭i 提交于 2019-11-28 04:45:27
I'm trying to do simple thing - after some entity saved (using http request) I want to navigate back to list route. The problem is : how to subscribe to success action (or may be reducer or effect?) here is my actions code: static SAVE_POST = '[POST] Save POST'; savePOST(Post): Action { return { type: PostActions.SAVE_POST, payload: Post }; } static SAVE_POST_SUCCESS = '[POST] Save POST Success'; savePOSTSuccess(Post): Action { console.log('action: savePostSuccess') return { type: PostActions.SAVE_POST_SUCCESS, payload:Post }; } i'm using Effects: @Effect() savePost$ = this.update$ .ofType

How to choose the Redux state shape for an app with list/detail views and pagination?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 02:49:05
Imagine I have a number of entries(say, users) in my database. I also have two routes, one for list, other for detail(where you can edit the entry). Now I'm struggling with how to approach the data structure. I'm thinking of two approaches and a kinda combination of both. Shared data set I navigate to /list , all of my users are downloaded from api a stored in redux store, under the key users , I also add some sort of users_offset and users_limit to render only part of the of the list I then navigate to /detail/<id> , and store currently_selected_user with <id> as the val... which means I will

Rx.Subject loses events

旧巷老猫 提交于 2019-11-28 02:08:50
Can anybody explain what the differents between these 3 variants? http://jsfiddle.net/8vx2g3fr/2/ First works as excpect, all events are processed. But second loses last event (3) Third loses second event (2) Could you please help me to understand what the issue is and how to make the third variant process all events? 1 let bs = new Rx.Subject(); bs .subscribe(v=>{ console.log("in", v); if (v % 2 == 0) { setTimeout(()=>{ console.log(" out", v, "->" , v + 1); bs.next(v+1); }, 0); } }); bs.next(0); bs.next(2); Output: in 0 in 2 out 0 -> 1 in 1 out 2 -> 3 in 3 2 let bs2 = new Rx.Subject(); bs2

Angular 2 update global state as a side effect of updating a certain state

拥有回忆 提交于 2019-11-28 02:02:40
I want to achieve setting a global state while also requesting data from an api and storing that in the state as well, but in another location than the global state. I'm calling this effect ( models.effects.ts ): @Effect() models$: Observable<Action> = this.actions$ .ofType(GET_MODELS) .switchMap(() => this.modelsApi.getModels()) .map(models => ({type: SET_MODELS, payload: models})) .catch((err: any) => Observable.of({type: GET_FAILURE, payload: {error: err}})) Now what I want to do is something like this: @Effect() models$: Observable<Action> = this.actions$ .ofType(GET_MODELS) .do(() => this

How to get current value of State object with @ngrx/store?

淺唱寂寞╮ 提交于 2019-11-27 19:17:13
问题 My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I'm doing it like this: constructor ( public _store: Store<AppState>, public _APIService:APIService) { const store$ = this._store.select ('StateReducer'); .../... let update = this.actions$.filter ( action => action.type==UPDATE ) .do( (action) => this._store.dispatch({type: REDUCER_UPDATING, payload : action.payload }) ) *** GET STATE ***==> .mergeMap ( action => store$.map

SwitchMap vs MergeMap in the #ngrx example

一世执手 提交于 2019-11-27 17:48:46
Below is code from the Ngrx example: https://github.com/ngrx/example-app/blob/master/src/effects/book.ts My question is why in the first @Effect, it uses switchMap while the others use mergeMap . Is that because the first @Effect is dealing with network, and with the switchMap you can cancel the previous network request if it's running? @Effect() search$ = this.updates$ .whenAction(BookActions.SEARCH) .map<string>(toPayload) .filter(query => query !== '') .switchMap(query => this.googleBooks.searchBooks(query) .map(books => this.bookActions.searchComplete(books)) .catch(() => Observable.of

What is store.select in ngrx

让人想犯罪 __ 提交于 2019-11-27 15:40:38
问题 I'm new to Redux and started with ngrx. I'm unable to understand the meaning of this line of code store.select : clock: Observable<Date>; this.clock = store.select('clock'); 回答1: In very simple terms select gives you back a slice of data from the application state wrapped into an Observable. What it means is, select operator gets the chunk of data you need and then it converts it into an Observable object. So, what you get back is an Observable that wraps the required data. To consume the