Skip to main content

getComputedInstance()

Retrieves the underlying computed instance for a given property created with the computed decorator.

Example

class Counter {
max = 100
count = atom(0)

@computed get remaining() {
return this.max - this.count.value
}
}

const c = new Counter()
const remaining = getComputedInstance(c, 'remaining')
remaining.value === 100 // true
c.count.set(13)
remaining.value === 87 // true

Signature

getComputedInstance<Obj, Prop>(obj: Obj, propertyName: Prop): Computed<Obj[Prop]>;

Type parameters

  • Obj extends object
  • Prop extends string | number | symbol

Parameters

NameType
objObj
propertyNameProp

Returns

Computed<Obj[Prop]>

Defined in: signia/src/Computed.ts:282