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

Function set

packages/mobx/src/api/object-api.ts:84–119  ·  view source on GitHub ↗
(obj: any, key: any, value?: any)

Source from the content-addressed store, hash-verified

82export function set<T extends Object>(obj: T, values: { [key: string]: any })
83export function set<T extends Object>(obj: T, key: PropertyKey, value: any)
84export function set(obj: any, key: any, value?: any): void {
85 if (arguments.length === 2 && !isObservableSet(obj)) {
86 startBatch()
87 const values = key
88 try {
89 for (let key in values) {
90 set(obj, key, values[key])
91 }
92 } finally {
93 endBatch()
94 }
95 return
96 }
97 if (isObservableObject(obj)) {
98 ;(obj as any as IIsObservableObject)[$mobx].set_(key, value)
99 } else if (isObservableMap(obj)) {
100 obj.set(key, value)
101 } else if (isObservableSet(obj)) {
102 obj.add(key)
103 } else if (isObservableArray(obj)) {
104 if (typeof key !== "number") {
105 key = parseInt(key, 10)
106 }
107 if (key < 0) {
108 die(`Invalid index: '${key}'`)
109 }
110 startBatch()
111 if (key >= obj.length) {
112 obj.length = key + 1
113 }
114 obj[key] = value
115 endBatch()
116 } else {
117 die(8)
118 }
119}
120
121export function remove<K, V>(obj: ObservableMap<K, V>, key: K)
122export function remove<T>(obj: ObservableSet<T>, key: T)

Callers 3

object-api.jsFile · 0.50
set.jsFile · 0.50
object-api.jsFile · 0.50

Calls 9

startBatchFunction · 0.85
endBatchFunction · 0.85
isObservableMapFunction · 0.85
dieFunction · 0.85
setMethod · 0.65
isObservableObjectFunction · 0.50
isObservableArrayFunction · 0.50
set_Method · 0.45
addMethod · 0.45

Tested by

no test coverage detected