MCPcopy
hub / github.com/vuejs/core / CustomRefImpl

Class CustomRefImpl

packages/reactivity/src/ref.ts:296–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296class CustomRefImpl<T, S = T> {
297 public dep: Dep
298
299 private readonly _get: ReturnType<CustomRefFactory<T, S>>['get']
300 private readonly _set: ReturnType<CustomRefFactory<T, S>>['set']
301
302 public readonly [ReactiveFlags.IS_REF] = true
303
304 public _value: T = undefined!
305
306 constructor(factory: CustomRefFactory<T, S>) {
307 const dep = (this.dep = new Dep())
308 const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep))
309 this._get = get
310 this._set = set
311 }
312
313 get value(): T {
314 return (this._value = this._get())
315 }
316
317 set value(newVal: S) {
318 this._set(newVal)
319 }
320}
321
322/**
323 * Creates a customized ref with explicit control over its dependency tracking

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected