Skip to content

Commit

Permalink
fix(type): remove makeObservable and makeAutoObservable function prox…
Browse files Browse the repository at this point in the history
…y option (#3717)
  • Loading branch information
liucan233 authored Jul 14, 2023
1 parent 9f80ed7 commit 55f78dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit 55f78dd

Please sign in to comment.