spierala / mini-rx-store

MiniRx - The reactive state management platform
https://mini-rx.io
Other
170 stars 9 forks source link

mini-rx-store: wrong deprecation warning for createFeatureStateSelector #217

Open spierala opened 7 months ago

spierala commented 7 months ago

image

In IntelliJ there is a wrong deprecation warning for createFeatureStateSelector.

This function is not deprecated. Only createFeatureSelector is deprecated.

I guess that the confusion comes from this typing:

image

carlos-ds commented 6 months ago

@spierala I can pick this up if you want but is the idea to remove createFeatureSelector completely in the next release? Or do you want to fix this but keep createFeatureSelector available?

spierala commented 6 months ago

You can pick this up for sure!

I would like to keep createFeatureSelector, maybe never remove it. Because NgRx has a createFeatureSelector. It makes refactor from NgRx to MiniRx slightly more easy :)

carlos-ds commented 5 months ago

@spierala in this case it's probably just easiest to duplicate the implementation? In my opinion, that makes it more clear which overloads are available for createFeatureStateSelector and what exactly is deprecated. The disadvantage obviously being that you'd have to make changes twice when the implementation changes.

/** @deprecated Use `createFeatureStateSelector` which is more in line with `createComponentStateSelector` */
export function createFeatureSelector<T>(featureKey?: string): Selector<object, T>;
/** @deprecated Use `createFeatureStateSelector` which is more in line with `createComponentStateSelector` */
export function createFeatureSelector<T, V>(featureKey: keyof T): Selector<T, V>;
/** @deprecated Use `createFeatureStateSelector` which is more in line with `createComponentStateSelector` */
export function createFeatureSelector(featureKey?: any): Selector<any, any> {
    if (featureKey) {
        return createSelector(
            (state: any) => state[featureKey],
            (featureState) => featureState
        );
    }
    return (state) => state;
}

export function createFeatureStateSelector<T>(featureKey?: string): Selector<object, T>;
export function createFeatureStateSelector<T, V>(featureKey: keyof T): Selector<T, V>;
export function createFeatureStateSelector(featureKey?: any): Selector<any, any> {
    if (featureKey) {
        return createSelector(
            (state: any) => state[featureKey],
            (featureState) => featureState
        );
    }
    return (state) => state; // Do not memoize: when used with FeatureStore there is a new state object created for every `setState`
}