exportfunction makeAutoObservable<T extends object, AdditionalKeysextendsPropertyKey = never>( target: T, overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: CreateObservableOptions ): T { // 此时当我们遇到这里明显不需要进入内部的场景,我们点击第二个选项 if (__DEV__) { if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) { die(`'makeAutoObservable' can only be used for classes that don't have a superclass`) } if (isObservableObject(target)) { die(`makeAutoObservable can only be used on objects not already made observable`) } }
// Optimization: avoid visiting protos // Assumes that annotation.make_/.extend_ works the same for plain objects if (isPlainObject(target)) { returnextendObservable(target, target, overrides, options) }
// Optimization: cache keys on proto // Assumes makeAutoObservable can be called only once per object and can't be used in subclass if (!target[keysSymbol]) { const proto = Object.getPrototypeOf(target) const keys = newSet([...ownKeys(target), ...ownKeys(proto)]) keys.delete("constructor") keys.delete($mobx) addHiddenProp(proto, keysSymbol, keys) }