ngrx

NgRx Get value without subscribing

泪湿孤枕 提交于 2020-01-15 10:37:28
问题 I am working my way through some ngrx tutorials and I think I'm starting to get my brain wrapped around it. What I don't understand is how to do something as simple as getting a value from the Store : Goal : Get a value from the store without having to subscribe to it. IE: store.myStoreProperty or store.getValue(<selector>) or ? From what I understand the only way to grab a value from the store is to do something like this: private readonly _store: Store<ApplicationState>; // ... this._store

Polling server after each server response + delay

巧了我就是萌 提交于 2020-01-15 07:45:11
问题 I am working on an effect, that will be polling server. What I want to achieve is as follows: 1) Send GET request to server 2) After response is received, wait 3 seconds 3) Send same GET request 4) After response is received, wait 3 seconds 5) Send same GET request ... and so on. The code that I have now, doesn't quite work, as it polls server every 3 seconds, no matter if response was received or not: @Effect() pollEntries$ = this.actions$.pipe( ofType(SubnetBrowserPageActions

Typescript import alias + barrel file

不羁的心 提交于 2020-01-15 03:23:30
问题 I spent a lot of time recently because of a particular behavior of something (and I could not identify the possible root cause) in angular/ngrx/typescript ecosystem. The scenario: I've built up some effects and I have exported them in a barrel file ( index.ts ): import {MyEffects} from './my.effects'; export const effects: any[] = [ MyEffects, ]; Then, in another barrel file, one level up in my directory structure, I have: import * as EFFECTS from './effects' export {EFFECTS}; And, finally,

Error building angular+ngrx 8 for production when using createReducer function

点点圈 提交于 2020-01-14 07:03:10
问题 Currently I am trying to build an Angular + NgRX 8 application with the new NgRX creator functions. But when I am building this for production, there appears the following error: Function calls are not supported in decorators but 'createReducer' was called in 'reducers'. In development mode there is no problem at all. The request reducer looks like export interface State extends EntityState<Request> { loading: boolean; error: any; } export const initialState = adapter.getInitialState({

Why use NGRX instead of constructor injected services?

爷,独闯天下 提交于 2020-01-13 10:08:13
问题 Wondering why one would use NGRX or NGXS for an Angular app instead of constructor injected services to handle component IO? Is it only to ensure that component properties references are never mutated without switching out the entire property value reference or is there more to it? Altnernative to NGRX per the answer I developed: Slice. I believe it does everything NgRx / NgXS does (With the exception of a time machine - but this is easy to implement via delta notifications - already

How do I mock selectors in nrgx 8 unit tests?

不想你离开。 提交于 2020-01-11 13:56:30
问题 I am learning to write unit tests for ngrx8 application using Jest. I am testing a component that has subscription to a selector in ngOnInit: ngOnInit(): void { this.store.pipe(select(someSelector(this.parameter))).subscribe((res: // some logic here }); } In the .spec.ts file I put provideMockStore in TestBed configuration: TestBed.configureTestingModule({ // ... providers: [ provideMockStore({ initialState, // defined somewhere above selectors: [ { selector: someSelector('param'), value: {a:

TypeError: unknown type returned

a 夏天 提交于 2020-01-07 01:55:47
问题 I am using ngrx/effects . I got this error: ORIGINAL EXCEPTION: TypeError: unknown type returned This is part of my codes: this.store.dispatch({ type: CHAT_LOAD_MESSAGES, payload: chatId }); @Effect() loadMessages$ = this.updates$ .whenAction(CHAT_LOAD_MESSAGES) .map<string>(toPayload) .do(chatId => console.log('chatId', chatId)) // Here I can get chatId .switchMapTo(chatId => this.chatService.loadMessages(chatId)) // The error comes out because of this line .do(res => console.log('res', res)

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

两盒软妹~` 提交于 2020-01-06 17:59:30
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

不羁的心 提交于 2020-01-06 17:59:21
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

Deadly 提交于 2020-01-06 17:58:59
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service