MCPcopy Index your code
hub / github.com/mobxjs/mobx / createObservable

Function createObservable

packages/mobx/src/api/observable.ts:105–149  ·  view source on GitHub ↗

* Turns an object, array or function into a reactive structure. * @param v the value which should become observable.

(v: any, arg2?: any, arg3?: any)

Source from the content-addressed store, hash-verified

103 * @param v the value which should become observable.
104 */
105function createObservable(v: any, arg2?: any, arg3?: any) {
106 // @observable someProp; (2022.3 Decorators)
107 if (is20223Decorator(arg2)) {
108 return observableAnnotation.decorate_20223_(v, arg2)
109 }
110
111 // @observable someProp;
112 if (isStringish(arg2)) {
113 storeAnnotation(v, arg2, observableAnnotation)
114 return
115 }
116
117 // already observable - ignore
118 if (isObservable(v)) {
119 return v
120 }
121
122 // plain object
123 if (isPlainObject(v)) {
124 return observable.object(v, arg2, arg3)
125 }
126
127 // Array
128 if (Array.isArray(v)) {
129 return observable.array(v, arg2)
130 }
131
132 // Map
133 if (isES6Map(v)) {
134 return observable.map(v, arg2)
135 }
136
137 // Set
138 if (isES6Set(v)) {
139 return observable.set(v, arg2)
140 }
141
142 // other object - ignore
143 if (typeof v === "object" && v !== null) {
144 return v
145 }
146
147 // anything else
148 return observable.box(v, arg2)
149}
150assign(createObservable, observableDecoratorAnnotation)
151
152export interface IObservableValueFactory {

Callers

nothing calls this directly

Calls 8

is20223DecoratorFunction · 0.85
isStringishFunction · 0.85
storeAnnotationFunction · 0.85
isES6MapFunction · 0.85
isES6SetFunction · 0.85
isObservableFunction · 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…