MCPcopy
hub / github.com/vueuse/vueuse / write

Function write

packages/core/useStorage/index.ts:242–261  ·  view source on GitHub ↗
(v: unknown)

Source from the content-addressed store, hash-verified

240 }
241
242 function write(v: unknown) {
243 try {
244 const oldValue = storage!.getItem(keyComputed.value)
245
246 if (v == null) {
247 dispatchWriteEvent(oldValue, null)
248 storage!.removeItem(keyComputed.value)
249 }
250 else {
251 const serialized = serializer.write(v as any)
252 if (oldValue !== serialized) {
253 storage!.setItem(keyComputed.value, serialized)
254 dispatchWriteEvent(oldValue, serialized)
255 }
256 }
257 }
258 catch (e) {
259 onError(e)
260 }
261 }
262
263 function read(event?: StorageEventLike) {
264 const rawValue = event

Callers 1

useStorageFunction · 0.70

Calls 5

dispatchWriteEventFunction · 0.85
onErrorFunction · 0.85
getItemMethod · 0.80
removeItemMethod · 0.80
setItemMethod · 0.80

Tested by

no test coverage detected