mobxjs / mobx

Simple, scalable state management.
http://mobx.js.org
MIT License
27.54k stars 1.77k forks source link

`CreateObservableOptions.equals` is ignored when creating arrays, maps, sets, and objects #3762

Open Nokel81 opened 1 year ago

Nokel81 commented 1 year ago

As the types for observable.array, observable.map, observable.set, and observable.object all imply:

export declare type CreateObservableOptions = {
    name?: string;
    equals?: IEqualsComparer<any>;
    deep?: boolean;
    defaultDecorator?: Annotation;
    proxy?: boolean;
    autoBind?: boolean;
};
export declare const defaultCreateObservableOptions: CreateObservableOptions;
export declare function asCreateObservableOptions(thing: any): CreateObservableOptions;
export declare function getEnhancerFromOptions(options: CreateObservableOptions): IEnhancer<any>;
export declare function getAnnotationFromOptions(options?: CreateObservableOptions): Annotation | undefined;
export declare function getEnhancerFromAnnotation(annotation?: Annotation): IEnhancer<any>;
export interface IObservableValueFactory {
    <T>(value: T, options?: CreateObservableOptions): IObservableValue<T>;
    <T>(value?: T, options?: CreateObservableOptions): IObservableValue<T | undefined>;
}
export interface IObservableFactory extends Annotation, PropertyDecorator {
    <T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>;
    <T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>;
    <K = any, V = any>(value: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
    <T extends object>(value: T, decorators?: AnnotationsMap<T, never>, options?: CreateObservableOptions): T;
    box: IObservableValueFactory;
    array: <T = any>(initialValues?: T[], options?: CreateObservableOptions) => IObservableArray<T>;
    set: <T = any>(initialValues?: IObservableSetInitialValues<T>, options?: CreateObservableOptions) => ObservableSet<T>;
    map: <K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions) => ObservableMap<K, V>;
    object: <T = any>(props: T, decorators?: AnnotationsMap<T, never>, options?: CreateObservableOptions) => T;
    /**
     * Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
     */
    ref: Annotation & PropertyDecorator;
    /**
     * Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
     */
    shallow: Annotation & PropertyDecorator;
    deep: Annotation & PropertyDecorator;
    struct: Annotation & PropertyDecorator;
}

all of the fields within CreateObservableOptions should apply to all the methods there, or else they should replay on different types.

urugator commented 1 year ago

equals should only be at box and observable(primitive | function). autoBind, deep, defaultDecorator are probably irrelevant for some of these as well. PR welcome.