ngxs-labs / entity-state

⏱ WIP: Entity adapter
48 stars 12 forks source link

Joining Selectors of two EntityState not working #209

Closed amollahi closed 4 years ago

amollahi commented 4 years ago

Well i was trying to mix the states in a selector, i try Static and Dynamic but neither of them work. I get as first value an empty array, which is correct, and after i get undefined. Both states after update have all the values.

I compiled the current master of the entity-state to include it as library.


// AuthorState extends EntityState<AuthorDTO>
    @Selector([LocationState])
    static entities2(
        state: EntityStateModel<AuthorDTO>,
        locationState: EntityStateModel<LocationDTO>
    ) {
        return Object.values(state.entities)
        .map(v => {
            v.bornLocation = locationState.entities[v.bornIdlocation];
            return v;
        });
    }

    static entities3() {
        return createSelector([this, LocationState], (state: EntityStateModel<AuthorDTO>, location: EntityStateModel<LocationDTO>) => {
            return Object.values(state.entities)
            .map(v => {
                v.bornLocation = location.entities[v.bornIdlocation];
                return v;
            });
        });
    }

//And later in the component 
    @Select(AuthorState.entities2)
    author1$: Observable<AuthorDTO[]>;
    @Select(AuthorState.entities3())
    author2$: Observable<AuthorDTO[]>;