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

Function shallowEnhancer

packages/mobx/src/types/modifiers.ts:53–78  ·  view source on GitHub ↗
(v, _, name)

Source from the content-addressed store, hash-verified

51}
52
53export function shallowEnhancer(v, _, name): any {
54 if (v === undefined || v === null) {
55 return v
56 }
57 if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
58 return v
59 }
60 if (Array.isArray(v)) {
61 return observable.array(v, { name, deep: false })
62 }
63 if (isPlainObject(v)) {
64 return observable.object(v, undefined, { name, deep: false })
65 }
66 if (isES6Map(v)) {
67 return observable.map(v, { name, deep: false })
68 }
69 if (isES6Set(v)) {
70 return observable.set(v, { name, deep: false })
71 }
72
73 if (__DEV__) {
74 die(
75 "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets"
76 )
77 }
78}
79
80export function referenceEnhancer(newValue?) {
81 // never turn into an observable

Callers

nothing calls this directly

Calls 8

isObservableMapFunction · 0.85
isES6MapFunction · 0.85
isES6SetFunction · 0.85
dieFunction · 0.85
isObservableObjectFunction · 0.70
isObservableArrayFunction · 0.70
setMethod · 0.65
isPlainObjectFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…