ngrx

Clone and then mutate approach in redux

时间秒杀一切 提交于 2019-12-11 06:13:59
问题 I've been reading stuff on redux for a while. And there is a strange thing for me. In most examples people give, all the copying logic is handled via reducers. I'm using typescript and want to adopt a more class-based approach. But maybe I'm missing something. Let's say I have a shopping Cart class. Along with cart reducer and cart actions. It looks the following way: export class Cart { private items:{[key:string]:number} = {}; constructor(items:{[key:string]:number} = {}) { Object.assign

Protractor wait for angular application to be stable

扶醉桌前 提交于 2019-12-11 06:10:46
问题 I have an issue when running e2e tests with Protractor. It seems the whenStable is being called too early (a fraction of a second early). I load the data via guards, populate the store and then the containers receive this data via selectors which then pass the data down to the components. My application is built with Angular 5 and ngrx 4. Is there a way to successfully get whenStable to trigger at the right time without creating my own function for checking if an element is present? Edited

Get current ngrx state without subscribe

孤者浪人 提交于 2019-12-11 05:57:12
问题 I'd like to use Ngrx for OAuth2 services and I need to get current store state without using subscribe. This is my OAuth function for getting token from localStorage: private oAuth2() { const token = JSON.parse(localStorage.getItem('oAuthToken')); if (token && token.access_token) { const headers = new Headers({ 'Authorization': 'Bearer ' + token.access_token }); return new RequestOptions({ headers: headers }); } } Is it possible to use Redux store instead of localStorage in this case? 回答1: I

What does a state mean in Angular application?

大城市里の小女人 提交于 2019-12-11 05:14:40
问题 I am new to NgRx and going through its documentation. But, at the beginning, I'm encountered with the following sentence: State is a single, immutable data structure. What does the state mean in simple words? Need some simple examples to understand this concept. Do I need to learn Flux and Redux to understand these concepts? 回答1: Simply put, a state in ngrx (or redux, or other state managment systems) is how your system is described in a single point in time. You can think about it as a plain

Karma unit test / STORE - state undefined

别说谁变了你拦得住时间么 提交于 2019-12-11 00:24:20
问题 Everything works OK when running the application but in the Account unit test it seems like none or my states have been initiated. Is there anything obvious I am doing wrong? Here is the error. Test error: The create selector in index.js is returning a function with undefined parameters but only during karma tests. Account.component.ts import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core'; import * as fromAuth from '../../../auth/store/reducers'; import { Store

ngrx - conditionally stop/remove Effect/Action

泄露秘密 提交于 2019-12-10 23:56:15
问题 I am currently building an application with Ionic2 and ngrx and I am trying to stop certian Actions if there is no network connection. With stop I mean to somehow make them invisible for other Effects and the store or stop them from further "propagating". Is there a way to do something like this? @Effect() checkNetworkConnection$ = this.actions$ .ofType(book.ActionTypes.LOAD_BOOKS, book.ActionTypes.CREATE_BOOK) .if(Network.connection === 'none') .do(() => new ShowNetworkAlertAction()) /

Ngrx store immutable state with an array?

别说谁变了你拦得住时间么 提交于 2019-12-10 18:27:17
问题 I'm planning to create a large application with Angular 5. I want to use Ngrx too to store the state of my app. But there is one thing I don't understand. Let's say that I have an object (I don't use classes or interfaces now for simplicity), that represents my state in a Store : let state = { x: 10, y: [1, 2, 3] }; In every article that I read the writers are using Object.assign() to create a copy of the state in a reducer. For example: ... case SET_X: return Object.assign({}, state, {x: 123

RXJS Wait for All Observables to Complete and Return Results

一世执手 提交于 2019-12-10 16:59:51
问题 I'm trying to create a RX stream that will execute a list of XHR calls async and then wait for them to complete before going to the next call. To help explain this could be written like this in normal JS: try { await* [ ...requests.map(r => angularHttpService.get(`/foo/bar/${r}`)) ]; } catch(e) { throw e } // do something This is the code I was trying but its running them individually and not waiting for them all to complete before proceeding. (This is a NGRX Effect stream so it is slightly

Why use .takeUntil() over .take(1) with Http service?

依然范特西╮ 提交于 2019-12-10 16:38:07
问题 Context: I am working on implementing @ngrx/effects within an @ngrx/store project and studying the example app. Question: In the BookEffects class file, line #50, why is takeUntil(...) used instead of take(1) ? Both would seem to accomplish the same thing in this case. @Injectable() export class BookEffects { constructor(private actions$: Actions, private googleBooks: GoogleBooksService) { } @Effect() search$: Observable<Action> = this.actions$ .ofType(book.ActionTypes.SEARCH) .debounceTime

sane way to pass/keep a value throwout a long pipe

安稳与你 提交于 2019-12-10 15:43:16
问题 Assuming i have the following rxjs pipe: start$.pip( map((id)=> {}), //I want to save the "id" value to be used in the end of the pipe map(...), switchMap(...), map(...), switchMap(...), map(...), switchMap(...), switchMap(...)//I need the original "id" value here ).subscribe() Is there a way to keep the 'id" value throughout the pip so it can be used at the end of the pipe? Motivation: It comes often in NGRX effects where i want to use the original payload data of the triggering source