MCPcopy
hub / github.com/mobxjs/mobx / makeObservable

Function makeObservable

packages/mobx/src/api/makeObservable.ts:27–46  ·  view source on GitHub ↗
(
    target: T,
    annotations?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
    options?: MakeObservableOptions
)

Source from the content-addressed store, hash-verified

25type MakeObservableOptions = Omit<CreateObservableOptions, "proxy">
26
27export function makeObservable<T extends object, AdditionalKeys extends PropertyKey = never>(
28 target: T,
29 annotations?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
30 options?: MakeObservableOptions
31): T {
32 initObservable(() => {
33 const adm: ObservableObjectAdministration = asObservableObject(target, options)[$mobx]
34 if (__DEV__ && annotations && target[storedAnnotationsSymbol]) {
35 die(
36 `makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.`
37 )
38 }
39 // Default to decorators
40 annotations ??= collectStoredAnnotations(target)
41
42 // Annotate
43 ownKeys(annotations).forEach(key => adm.make_(key, annotations![key]))
44 })
45 return target
46}
47
48// proto[keysSymbol] = new Set<PropertyKey>()
49const keysSymbol = Symbol("mobx-keys")

Callers 15

constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90

Calls 7

initObservableFunction · 0.85
dieFunction · 0.85
collectStoredAnnotationsFunction · 0.85
ownKeysFunction · 0.85
make_Method · 0.80
forEachMethod · 0.65
asObservableObjectFunction · 0.50

Tested by 15

constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72
constructorMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…