ngrx

Angular 5 Ngrx State lost during browser page refresh

柔情痞子 提交于 2019-11-29 15:03:45
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 ? 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 sessionStorage accomplish the exact same thing and have the same API, but with sessionStorage the data is

Getting current state in ngrx

巧了我就是萌 提交于 2019-11-29 12:47:48
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 . The ngrx-store is a ReplaySubject of length=1 , this means only 1(the latest) value is cached and replayed on subscribe - so take(1) will resolve to the latest value. 来源: https://stackoverflow.com

Waiting for ngrx action before loading page with URL parameter

旧巷老猫 提交于 2019-11-29 07:08:52
I'm building an ng2 application using ngrx. When the app is launched a web service is called to get initial data, once this data is fetched I create an INIT_DONE action. My State looks like this : export interface State { documents: Document[]; selectedDocument: Document } When I go to the page /mypage/456 where 456 is a url parameter, I need to get some of the fetched data so I get the URL parameter like this : ngOnInit() { this.paramSubscription = this.route.params .select<string>('id') .map((id) => new SelectAction(id)) .subscribe(this.store); } The SELECT_ACTION finds the element in the

What is store.select in ngrx

青春壹個敷衍的年華 提交于 2019-11-29 01:09:55
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'); 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 data you need to subscribe to it. Lets see a very basic example. Lets define the model of our store export

How to get access of the state tree in effects? (@ngrx/effects 2.x)

杀马特。学长 韩版系。学妹 提交于 2019-11-28 23:05:15
I am updating @ngrx/effects from 1.x to 2.x In 1.x I have access of state tree in effect: constructor(private updates$: StateUpdates<AppState>) {} @Effect() bar$ = this.updates$ .whenAction(Actions.FOO) .map(obj => obj.state.user.isCool) .distinctUntilChanged() .filter(x => x) .map(() => ({ type: Actions.BAR })); Now in 2.x, it only gives me action. Is there still a way to get access of the state tree? Or should I avoid using like this because it is not a good practice? constructor(private actions$: Actions) {} @Effect() bar$ = this.actions$ .ofType(ActionTypes.FOO) .map((obj: any) => {

Reconnecting a websocket in Angular and rxjs?

Deadly 提交于 2019-11-28 21:33:56
I have a ngrx/store (v2.2.2) and rxjs (v5.1.0) based application that listens to a web socket for incoming data using an observable. When I start the application I receive incoming data flawlessly. However after a while (updates are coming in quite infrequently) the connection seem to get lost and I don't get anymore incoming data. My code: The service import { Injectable, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; @Injectable() export class MemberService implements OnInit { private websocket: any; private destination: string = "wss://notessensei.mybluemix.net/ws/time";

What is the purpose of ngrx/effects library?

纵饮孤独 提交于 2019-11-28 17:14:05
I have failed to find any usefull information about this library or what is the purpose of it. It seems like ngrx/effects explain this library to developers who already know this concept and gives a bigginer example on how to code. My questions: What are sources of actions? What is the purpose of ngrx/effects library;what is the downside of only using ngrx/store? When it is recommended to be used? Does it support angular rc 5+? How do we configure it in rc 5+? Thanks! George Zhou The topic is too wide. It will be like a tutorial. I will give it a try anyway. In a normal case, you will have an

NgrxStore and Angular - Use the async pipe massively or subscribe just once in the constructor

允我心安 提交于 2019-11-28 17:11:34
I am starting to look at ngrx Store and I see the convenience to use the Angular async pipe. At the same time I am not sure whether using the Angular async pipe massively is a good choice. I make a simple example. Let's assume that in the same template I need to show different attributes of an object (e.g. a Person) which is retrieved from the Store. A piece of template code could be <div>{{(person$ | async).name}}</div> <div>{{(person$ | async).address}}</div> <div>{{(person$ | async).age}}</div> while the component class constructor would have export class MyComponent { person$: Observable

What are benefits of using store (ngrx) in angular 2

限于喜欢 提交于 2019-11-28 16:04:28
I'm working on a angular 1.x.x project and thinking about upgrading my code to angular 2 . Now in my project I have many services(factory) for handling data which almost keep data in js arrays(both cache and storage) and process these data by using underscore for handling arrays. I found that many examples in angular2 using ngrx. What are benefits of using store compare to use data services to handle data? Do I need multiple store for my app if I have multiple data type (stock, order, customer...)? How can I structure (design) my app to deal with multiple data types like these? Even though

@ngrx Effect does not run the second time

北城余情 提交于 2019-11-28 12:10:02
I've just started learning about @ngrx/store and @ngrx.effects and have created my first effect in my Angular/Ionic app. It runs ok the first time but if I dispatch the event to the store again (i.e when clicking the button again), nothing happens (no network call is made, nothing in console logs). Is there something obvious I'm doing wrong? Here's the effect: @Effect() event_response$ = this.action$ .ofType(SEND_EVENT_RESPONSE_ACTION) .map(toPayload) .switchMap((payload) => this.myService.eventResponse(payload.eventId,payload.response)) .map(data => new SentEventResponseAction(data)) .catch(