Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(type): remove makeObservable and makeAutoObservable function proxy option #3717

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-ducks-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

remove proxy option for makeObservable and makeAutoObservable
2 changes: 1 addition & 1 deletion docs/observable-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ The above APIs take an optional `options` argument which is an object that suppo
- **`autoBind: true`** uses `action.bound`/`flow.bound` by default, rather than `action`/`flow`. Does not affect explicitely annotated members.
- **`deep: false`** uses `observable.ref` by default, rather than `observable`. Does not affect explicitely annotated members.
- **`name: <string>`** gives the object a debug name that is printed in error messages and reflection APIs.
- **`proxy: false`** forces `observable(thing)` to use non-[**proxy**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) implementation. This is a good option if the shape of the object will not change over time, as non-proxied objects are easier to debug and faster. See [avoiding proxies](#avoid-proxies).
- **`proxy: false`** forces `observable(thing)` to use non-[**proxy**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) implementation. This is a good option if the shape of the object will not change over time, as non-proxied objects are easier to debug and faster. This option is **not** available for `make(Auto)Observable`, see [avoiding proxies](#avoid-proxies).

<details id="one-options-per-target"><summary>**Note:** options are *sticky* and can be provided only once<a href="#one-options-per-target" class="tip-anchor"></a></summary>
`options` argument can be provided only for `target` that is NOT observable yet.<br>
Expand Down
6 changes: 4 additions & 2 deletions packages/mobx/src/api/makeObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import {
// Fixes: https://github.com/mobxjs/mobx/issues/2325#issuecomment-691070022
type NoInfer<T> = [T][T extends any ? 0 : never]

type MakeObservableOptions = Omit<CreateObservableOptions, "proxy">

export function makeObservable<T extends object, AdditionalKeys extends PropertyKey = never>(
target: T,
annotations?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
options?: CreateObservableOptions
options?: MakeObservableOptions
): T {
const adm: ObservableObjectAdministration = asObservableObject(target, options)[$mobx]
startBatch()
Expand All @@ -53,7 +55,7 @@ const keysSymbol = Symbol("mobx-keys")
export function makeAutoObservable<T extends object, AdditionalKeys extends PropertyKey = never>(
target: T,
overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
options?: CreateObservableOptions
options?: MakeObservableOptions
): T {
if (__DEV__) {
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
Expand Down