ngrx-store

No provider for Store! Error at injectionError

倾然丶 夕夏残阳落幕 提交于 2019-12-24 01:53:40
问题 app.component.html <page-router-outlet></page-router-outlet> app.component.ts import 'rxjs/add/operator/let'; import { Component, ViewEncapsulation } from '@angular/core'; import { EchoesState, getSidebarCollapsed$ } from './core/store'; import { Store } from '@ngrx/store'; @Component({ selector: "ns-app", templateUrl: "app.component.html", }) export class AppComponent { constructor(private store: Store<EchoesState>){} } app.module.ts import 'nativescript-localstorage'; import { NgModule, NO

Create non-memoized selector on ngrx

半城伤御伤魂 提交于 2019-12-23 14:20:10
问题 Is it possible to create a non-memoized selector on ngrx? I have a very small selector to check whether a value in the store is greater than Date.now(). export const selectAuthState = createFeatureSelector<AuthState>('auth'); export const hasTimeout = createSelector( selectAuthState, state => state.timeout < Date.now() ); As expected, this selector is not useful since it won't be recalculated unless I change the value of timeout . Is there any way to make the selector non-memoized, so that it

Create non-memoized selector on ngrx

梦想与她 提交于 2019-12-23 14:19:24
问题 Is it possible to create a non-memoized selector on ngrx? I have a very small selector to check whether a value in the store is greater than Date.now(). export const selectAuthState = createFeatureSelector<AuthState>('auth'); export const hasTimeout = createSelector( selectAuthState, state => state.timeout < Date.now() ); As expected, this selector is not useful since it won't be recalculated unless I change the value of timeout . Is there any way to make the selector non-memoized, so that it

Angular - “TypeError: Cannot freeze” when dispatching an action

瘦欲@ 提交于 2019-12-23 09:36:35
问题 I'm working on an angular app that uses ngrx store & effects. I get "TypeError: Cannot freeze" error when dispatching an action from my component. I wrote it for a file upload feature. I think that I'm mutating the state but cannot figure out where and how to solve it. Here's my detailed code: Actions: export enum FileUploadActionTypes { UploadFile = '[File Upload] Upload File', UploadFileSuccess = '[File Upload] Upload File Success', UploadFileFailure = '[File Upload] Upload File Failure' }

ngrx store subscription not called when state changes

偶尔善良 提交于 2019-12-21 09:35:04
问题 I am creating an application with dummy data defined in my service. In one component, I have the following function that deletes a product: removeItem(productId: string) { this.cartService.removeItem(productId); } and the service as follows: removeItem(productId: string) { const itemIndex = this.cart.products.findIndex(el => el.id === productId); if (itemIndex > -1) { this.cart.products.splice(itemIndex, 1); return Observable.of(this.cart) .subscribe((cartResponse: Cart) => { this.store

Angular 6 - Why use @ngrx/store rather than service injection

▼魔方 西西 提交于 2019-12-20 08:23:37
问题 I am recently learning Angular 6 with @ngrx/store while one of the tutorial is to use @ngrx/store for state management, however I don't understand the benefit of using @ngrx/store behind the scene. For example, for a simple login and signup action, previously by using the service(Let's call it AuthService) we might use it to call the backend api, store "userInfo" or "token" in the AuthService, redirect user to "HOME" page and we can inject AuthService in any component where we need to get the

How to unsubscribe from ngrx/store?

自闭症网瘾萝莉.ら 提交于 2019-12-18 19:30:13
问题 I have a component which gets its data from subscribing to a store. this.store.select('somedata').subscribe((state: any) => { this.somedata = state.data; }); I want to unsubscribe from this subscription when component is no more, in other places where I am subscribing to some observable, something like this: this.service.data.subscribe( (result: any) => {//data} ); I unsubscribed it on ngOnOnDestroy, like this: ngOnDestroy(){ this.service.data.unsubscribe(); } But in case of store I'm not

Providing root reducer in @ngrx/store 4.0

丶灬走出姿态 提交于 2019-12-18 12:34:17
问题 In @ngrx/store 2.0 we could provide the root reducer as a function and from there we split our logic inside the application. After I updated to @ngrx/store 4.0 I cannot use this feature any more from what I can see the reducers need to be a map of reducers which will create objects under the same keys in the state. Is there a way to use the old behavoir in @ngrx/store 4.0 In my state components are aware one of another and I need to be able to split my state dynamically also I need to be able

Providing root reducer in @ngrx/store 4.0

帅比萌擦擦* 提交于 2019-12-18 12:34:14
问题 In @ngrx/store 2.0 we could provide the root reducer as a function and from there we split our logic inside the application. After I updated to @ngrx/store 4.0 I cannot use this feature any more from what I can see the reducers need to be a map of reducers which will create objects under the same keys in the state. Is there a way to use the old behavoir in @ngrx/store 4.0 In my state components are aware one of another and I need to be able to split my state dynamically also I need to be able

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 = {},