MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / interceptPropertySet

Function interceptPropertySet

packages/shared/src/utils.ts:79–109  ·  view source on GitHub ↗
(
    obj: TObject,
    key: TKey,
    cb: (value: TObject[TKey]) => void,
)

Source from the content-addressed store, hash-verified

77}
78
79export function interceptPropertySet<TObject extends object, TKey extends keyof TObject>(
80 obj: TObject,
81 key: TKey,
82 cb: (value: TObject[TKey]) => void,
83): void {
84 const descriptor = Object.getOwnPropertyDescriptor(obj, key)
85 if (!descriptor) {
86 let value: TObject[TKey] = obj[key]
87 Object.defineProperty(obj, key, {
88 set(newValue) {
89 value = newValue
90 cb(newValue)
91 },
92 get() {
93 return value
94 },
95 })
96 return
97 }
98 const {set} = descriptor
99 if (!set) return
100 Object.defineProperty(obj, key, {
101 set(value) {
102 cb(value)
103 set.call(this, value)
104 },
105 get() {
106 return descriptor.get?.call(this)
107 },
108 })
109}
110
111// TODO fix this in solid-primitives
112export const asArray = <T>(value: T): (T extends any[] ? T[number] : T)[] =>

Callers 2

onSolidDevDetectFunction · 0.90
onSolidDevtoolsDetectFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…