by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 03 02:34
    brandonroberts commented #2604
  • Jul 03 01:41
    alex-okrushko commented #2604
  • Jul 03 00:40
    alex-okrushko opened #2605
  • Jul 03 00:21

    alex-okrushko on init-value

    feat(component-store): remove q… (compare)

  • Jul 02 19:52
    m00zi commented #2604
  • Jul 02 18:14
    brandonroberts commented #2604
  • Jul 02 17:44
    timdeschryver commented #2604
  • Jul 02 17:44
    timdeschryver labeled #2604
  • Jul 02 14:13
    m00zi opened #2604
  • Jul 02 11:50

    brandonroberts on component-store-schematics

    (compare)

  • Jul 02 11:50

    brandonroberts on master

    feat(component-store): add ng-a… (compare)

  • Jul 02 11:50
    brandonroberts closed #2598
  • Jul 02 11:50
    brandonroberts closed #2569
  • Jul 02 05:40
    ngrxbot commented #2598
  • Jul 02 05:30
    timdeschryver synchronize #2598
  • Jul 02 05:30

    timdeschryver on component-store-schematics

    build(component-store): add sch… (compare)

  • Jul 01 11:41
    yusijs commented #2592
  • Jul 01 11:22
    timdeschryver commented #2592
  • Jul 01 10:57
    yusijs commented #2592
  • Jun 30 16:21
    naticaceres commented #2434
Derek
@derekkite

@anno1985 if the reference of the object is the same as the memoized reference it doesn't fire. So even if your state is a new reference, an object within that state {...state} will be the same reference. You need to compose your selectors, where each selector extracts a specific property. If the state changes, the composed selector will run until it hits the objectreference === memoizedobjectreference.

And yes, that is how you do it. map(id => entities[id)...

nunofreitasbotelho
@nunofreitasbotelho

Hi, i have a few observables loaded when i init my views with simple things like the position of the cursor or the zoom applied.
On my query state i select the correspondant value from the store like this:

this.zoomLevel$ = this.store.pipe(
      select(LayoutState.mapZoomLevel)
    );

Usually i would subscribe to the values and update a local variable with the new value from the store, but for things like the zoom level i dont really need to store it, i just pass it down to other components.

Situation has changed and i now would like to save a snapshot of the values. Basically, i just need a single object with the values, but the only way i know is to query the values, then subscribe and update local variables, which will bloat my code...

How can i get the value directly from the observable?

Sami Al Khatib
@alsami
@nunofreitasbotelho you can pass it into your child component like that via an input:
<my-map-component [zoomLevel]="zoomLevel$ | async"></my-map-component>
This way, angular will subscribe and unsubscribe the observable.
tinyg
@tinyg
Hi All, I'm having a tough time trying to get my unit tests running for a module. The module relies on another module to inject various bits of store state and that module uses imports: [... StoreModule.forFeature(...) ] in its module init. In the module I'm trying to test, when I try to use the provideMockStore<State>({ initialState }), then I get an error NullInjectorError: No provider for StoreRootModule!
I assume this is maybe because provideMockStore doesn't provide StoreRootModule? but not sure what I could do to fix it...
tinyg
@tinyg
If I add StoreModule.forRoot({}) to my imports then I get: WARN: '@ngrx/store: The feature name "core" does not exist in the state, therefore createFeatureSelector cannot access it. Be sure it is imported in a loaded module using StoreModule.forRoot('core', ...) or StoreModule.forFeature('core', ...). If the default state is intended to be undefined, as is the case with router state, this development-only warning mess
tinyg
@tinyg
hmm - if I add "core": {} to my initialState then it stops complaining - still doesn't work properly but doesn't complain 🙂
tinyg
@tinyg
Ended up just using the real store - seemed to work better than the mock store in this case
PooSham
@PooSham
Is it the intended behavior that effects are still subscribed to when changing route to a new feature? Not sure if it's intended, a bug, or just me doing something wrong.
PooSham
@PooSham
For clarity on my issue: I have a project with multiple lazy-loaded features. In one of them, I have an effect that listens to actions of type routerNavigatedAction from @ngrx/router-store, like this:
changeRoute$ = createEffect(() =>
    this.actions$.pipe(
        ofType(routerNavigatedAction),
        mergeMap(action => 
            this.http.get("/api/someresource").pipe(map(x => myFeatureActions.load.success(x)))
        )))
But when I go to another part of the website, loading another feature (ie a module loaded under a certain route), I can still see these calls being made. So the observable inside the changeRoute$ effect is not being unsubscribed. Am I doing something wrong? Or is it a bug?
PooSham
@PooSham
My workaround right now is to do filter(action => action.payload.routerState.url.startsWith("/myfeature")) after the ofType, but I don't like it very much.
likwidgames
@likwidgames
Anyone use NGRX Data with custom effects?
Phil Mayfield
@philmayfield
I have a (presumably) common scenario where I have an entity adapter store slice, selector to read them as a list, and displaying them in a component template via async pipe, in this case as a list of cards. It all works great, the issue I have however is that when I push an update to the store for one of the items, the selector spits out the entire list again. Annoyingly, the list blinks or worse yet - runs animations at this moment of re-hydration, and overall looks kind of janky, even though it all technically works well. Anyone dealt with something similar?
rjdugar
@rjdugar
Hello All , I am new to ngrx recently implemented one feature -- I am getting following error -- ERROR TypeError: Cannot read property 'entities' of undefined
at selectEntities (entity.js:65)

core.js:6228 ERROR TypeError: Cannot read property 'entities' of undefined
at selectEntities (entity.js:65)
at store.js:1061
at memoized (store.js:976)
at defaultStateFn (store.js:1016)
at store.js:1070
at memoized (store.js:976)
at store.js:1015
at Array.map (<anonymous>)
at defaultStateFn (store.js:1011)
at store.js:1070 -----------Reducer code -------------------------------------import {EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'

// import {BodyMap} from '@app/core'

import {BodyMapActions, BodyMapTypes} from '../actions'

export interface BodyMapState extends EntityState<any> {
loaded: boolean
loading: boolean
}

export const adapter: EntityAdapter<any> = createEntityAdapter<any>()

export const initialBodyMapState: BodyMapState = adapter.getInitialState({
loaded: false,
loading: false
})

export function bodyMapReducer(state: BodyMapState = initialBodyMapState, actions: BodyMapActions): BodyMapState {
switch(actions.type) {
case BodyMapTypes.CREATE_BODY_MAP: {
return adapter.addOne(actions.payload.bodymap, {
...state,
loading: false,
loaded: true
})
}
case BodyMapTypes.LOAD_BODY_MAPS:
break
case BodyMapTypes.LOAD_BODY_MAPS_SUCCESS:
return adapter.addAll(actions.payload, {
...state,
loaded: true,
loading: false
})
case BodyMapTypes.LOAD_BODY_MAPS_FAIL:
break
}
}

export const getBodyMapEntities = (state: BodyMapState): {[id: number]:any} => {
return state.entities;
}

export const { selectIds, selectEntities, selectAll } = adapter.getSelectors()

-----------Reducer code -------------------------------------
import {EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'

// import {BodyMap} from '@app/core'

import {BodyMapActions, BodyMapTypes} from '../actions'

export interface BodyMapState extends EntityState<any> {
loaded: boolean
loading: boolean
}

export const adapter: EntityAdapter<any> = createEntityAdapter<any>()

export const initialBodyMapState: BodyMapState = adapter.getInitialState({
loaded: false,
loading: false
})

export function bodyMapReducer(state: BodyMapState = initialBodyMapState, actions: BodyMapActions): BodyMapState {
switch(actions.type) {
case BodyMapTypes.CREATE_BODY_MAP: {
return adapter.addOne(actions.payload.bodymap, {
...state,
loading: false,
loaded: true
})
}
case BodyMapTypes.LOAD_BODY_MAPS:
break
case BodyMapTypes.LOAD_BODY_MAPS_SUCCESS:
return adapter.addAll(actions.payload, {
...state,
loaded: true,
loading: false
})
case BodyMapTypes.LOAD_BODY_MAPS_FAIL:
break
}
}

export const getBodyMapEntities = (state: BodyMapState): {[id: number]:any} => {
return state.entities;
}

export const { selectIds, selectEntities, selectAll } = adapter.getSelectors()

rjdugar
@rjdugar
Selector code -----

import { createSelector } from "@ngrx/store";
import { BodyMapState, getBodyMapEntities } from "../reducers/body-map.reducer";
import { getBodyState, BodyState } from "../reducers";
import { selectAll, selectEntities, selectIds } from "../reducers/body-map.reducer";
import { Dictionary } from "@ngrx/entity";
import { selectAllCaseEntities } from "@app/core";

export const selectBodyMapState = createSelector(
getBodyState,
(state: BodyState): BodyMapState => {
return state.bodyMap
}
)

export const selectAllEntities = createSelector(
selectBodyMapState,
selectEntities
)

export const selectBodyMapIds = createSelector(
selectBodyMapState,
selectIds
)

export const selectAllBodyMaps = createSelector(
selectBodyMapState,
selectAll
)

export const getAllBodyMapEntites = createSelector(
selectBodyMapState,
getBodyMapEntities
)

export const selectAllBodyMapEntities = createSelector(
selectAllEntities,
selectBodyMapIds,
(skeches: Dictionary<any>):any => {
const key = Object.keys(skeches)[0]
return skeches[key]

}

)

Any feedback.. ?
nasreddine skandrani
@nasreddineskandrani
@timdeschryver long time no see.
this PR is a game changer for a lot of things in case you didnt see it yet microsoft/TypeScript#39094
Phil Mayfield
@philmayfield
@rjdugar I'd guess its coming from your const getBodyMapEntities, which kind of looks like it wants to be a selector. But it shouldnt be needed as your adapteralready provides a selectAllEntities selector for you.
RoboZoom
@RoboZoom
for EntityAdapters in NgRx, I'm declaring a sort comparer, but the selectors are not returning a sorted list
The adapter and sort are very basic:
const basicPatientAdapter: EntityAdapter<sPatient> = createEntityAdapter<
  sPatient
>({
  sortComparer: (a: sPatient, b: sPatient) =>
    a.Surname.localeCompare(b.Surname),
});
Anything I'm doing weird/wrong here?
Derek
@derekkite
@RoboZoom the id's will be sorted
RoboZoom
@RoboZoom
@derekkite - that's not happening either - my selector is presenting objects in the order that they are added to the entity list
Derek
@derekkite
@RoboZoom what does the selector look like?
RoboZoom
@RoboZoom

@derekkite

export const {
  selectAll,
  selectEntities,
  selectIds,
  selectTotal,
} = basicPatientAdapter.getSelectors();

export const patientState = (state: index.State) => state.patients;
export const getPatients = createSelector(patientState, selectEntities);

I'm using getPatients, but have some post-processing to get to the dataslice that I need in a service, which is doing an rxjs map iterating like this:

  map((p) => {
        let arr: iSPatient[] = [];
        for (let o in p) {
// much simplified
     array.push(o)
  }
return array
}
Derek
@derekkite
the sorted list is in selectIds. The entities aren't sorted, they are {[id]: entitytype}
RoboZoom
@RoboZoom
bah - I think you've told me this before
so if I just get the ids, do I need to create a new selector which merges that with entities?
or is there an easier way
never mind
I found some old code of mine where you probably told me this the first time
which is exactly what I just suggested, combining Ids and entities to create an ordered dictionary
RoboZoom
@RoboZoom
Thanks for your help @derekkite
Derek
@derekkite
no problem
RoboZoom
@RoboZoom
I hate when I ask questions twice :)
rraya
@rraya

Hi everyone!

I have a question about ngrx and custom elements.... My app has a state and is built as a custom element. This custom element is used twice by a index.html and my problem is that the second instance of the custom element overwrite the state of the first instance.

My first thought was to use an injection token StoreModule.forRoot(REDUCER_TOKEN) when I'm definiting the main module, but the problem keeps. Any idea/clue/help is really welcome!

Colton Williams
@coltonneil

Hello!

Working on re-hydrating state from local storage, just one piece, the logged in user. I know there are libraries, or I could do this with a custom meta reducer but I just wanted to see if there was any reason I shouldn't just handle it in my initialState:

export const initialLoginServiceState: LoginServiceState = {
  user: JSON.parse(localStorage.getItem('user')) ?? null,
};
nunofreitasbotelho
@nunofreitasbotelho

Hi guys, i hope i can get some clarification on this.
When loading a view, i run a queryState on my constructor. As an example, take this:

this.settings$ = this.store.pipe(
      select(SessionState.currentSettings)
    );

This means that i get the observable from the state, right?

So, on ngOnInit i subscribe to the observable and i get the settings like this:

this.settings$.pipe(takeUntil(this.destroy$))
      .subscribe(settings => this.settings = settings);

Even tho i'm not sure if its the best way, this worked to far for me.

Now i've been working on something else that i need to take some part of the settings (or the whole settings, it doesnt matter) on a separate function. I do it like this, inside said function:

let tempSettings;
    this.settings$.pipe(take(1))
      .subscribe(settings => {
        tempSettings = settings.partOfSettings;
      });

Few assumptions that might need correction:
I now have 2 subscriptions for a brief moment. The first one keeps watching until i destroy the component and the second one finishes after taking the settings one time, am i right? Or does the second one destroy the first one on the process?

For the settings example i can get the local values that are already stored, but some other states are not needed on the view itself, just on that brief moment, hence why i'm using the take(1) approach. Is there a better way to do this? Some parts of the state wont be change during the life of the view, is there any way to get the value with something like this(which wont work), and not getting the observable but the actual value:

const temp = this.store.pipe(
      select(SessionState.currentSettings)
    );

Thanks in advance

Piotr Pyśk
@piotter121
@brandonroberts Is ngrx/platform@9.2.0 officially supporting Angular 10, or we have to wait to the 10th release? If we do, when could it be?
Derek
@derekkite

@nunofreitasbotelho here is what I would do.

this.settings$ = this.store.pipe(
      select(SessionState.currentSettings),
      tap(s => this.separatefunctionneedingstate(s)),
      map(settingsstate => shape into what you need for the view),
    );

then in the view

{{settings$ | async}}

then you don't need to unsubscribe.

nunofreitasbotelho
@nunofreitasbotelho
Seems neat @derekkite. I will try that out, thanks!
Chuck Blaine
@cblaine
Does anybody have a link or something to an example of how to test feature state?
going crazy here
De Giovanni
@tamyfabius
hello everyone, is this someone has an idea of ​​how to manage a refresh token with ngrx in the interceptor ?
felixunivers
@felixunivers

Good day to all. My first try of this support system.

Is there a way to change DefaultDataServiceConfig property on an active instance of EntityCollectionServiceBase<T> ?

For example if I want to allow a user to adjust property of: timeout to a longer interval and let him re-fetch the HTTP data via get on a given entitity service.

For more details I have an un-ansewered question on StackOverflow - here
Thx