ngrx

Chaining http calls in angular 2 in a for loop

你离开我真会死。 提交于 2019-12-18 05:13:09
问题 I have some code that looks like //service.ts addProduct(productId) { this.http.post('someUrl', ReqData).map(json).subscribe(doStuff); } //component.ts addAllproducts(productsIds) { productIds.forEach(productId => service.addProduct(productId); } What I want is to be able to wait for each call to finish before calling for the next productId, without using window.setTimeout .. 回答1: First return the observable from your service method: addProduct(productId) { return this.http.post('someUrl',

Waiting for ngrx action before loading page with URL parameter

馋奶兔 提交于 2019-12-18 04:50:27
问题 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')

Reconnecting a websocket in Angular and rxjs?

痞子三分冷 提交于 2019-12-17 23:43:04
问题 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

Reconnecting a websocket in Angular and rxjs?

☆樱花仙子☆ 提交于 2019-12-17 23:39:34
问题 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

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

谁说胖子不能爱 提交于 2019-12-17 22:32:32
问题 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}}<

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

白昼怎懂夜的黑 提交于 2019-12-17 17:21:09
问题 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

Store vs Store<T>

拜拜、爱过 提交于 2019-12-13 18:03:25
问题 I'm pretty much a novice with the redux pattern and have just started using ngrx . It's awesome and it's something I want to use as much as possible, but I have a couple of questions regarding the Store concept. I will try to describe the problem through a few samples and ask my question at the end of this post. Let's start with the AppState interface and reducers: export interface AppState{ people: Person[], events: Event[] } //events reducer export function eventsReducer(state: any = {},

Data transformation in Class vs Reducer (ngrx/redux)

本小妞迷上赌 提交于 2019-12-13 16:04:59
问题 Using ngrx/redux, and following the ngrx example app as close as possible. Now I'm doing this somewhere in the application: get totalItems (): number { return sumBy(this._data.items, 'metadata.value'); } Where the _data is the raw async data from a remote server, and is part of some data of a User . Now I have some options: 1. Create a Class User constructor (public _data: UserResponse) {} And have some methods like: get name (): string { return this._data.name; } get address (): string {

Angular router guard and ROUTER_NAVIGATION effect order

时光毁灭记忆、已成空白 提交于 2019-12-13 12:12:23
问题 There is a simple (Angular 4) route guard, which waits for some data to be loaded from backend: @Injectable() export class ContractsLoadedGuard implements CanActivate { constructor(private store: Store<State>) { } waitForData(): Observable<boolean> { return this.store.select(state => state.contracts) .map(contractList => !!contractList) .filter(loaded => loaded) .take(1); } canActivate(): Observable<boolean> { return this.waitForData(); } } Routing: const routes: Routes = [ { path: 'app-list'

Lazy Feature Modules architecture migration to NGRX: Angular 8

余生颓废 提交于 2019-12-13 09:28:59
问题 Hey guys currently i am working in an application with Lazy features modules architecture implemented. Below you can see how the project is structured. Since the application is keep on growing we decided to migrate it to Ngrx. As is a new pattern for me i am searching for migration guidelines but i can only find ngrx guidelines when creating a project from scratch. Could you please give me some hints, guidelines,where should i be careful , and possibly some steps summary? Thanks you. 回答1: