Skip to main content

Module: decorators/computed

Functions​

computed​

▸ computed(target, key, descriptor): any

Description​

You can use @computed to decorate a getter function for derived data, which quickly solves performance problems for computing derived data.

if you want to use @computed with non-manually maintained dependencies, you should enable auto computed feature by setting 'autoComputed' to 'true' in the dev options.

Example​

class Shop {
@state
fruits = [];

@state
vegetables = [];

@computed(({ fruits, vegetables }: Shop) => [fruits, fruits])
get sum() {
return this.fruits.length + this.vegetables.length;
}
}

Parameters​

NameType
targetobject
keystring
descriptorTypedPropertyDescriptor<any>

Returns​

any

Defined in​

packages/reactant-module/src/decorators/computed.ts:11

▸ computed(depsCallback): (target: object, key: string, descriptor: TypedPropertyDescriptor<any>) => any

Description​

You can use @computed to decorate a getter function for derived data, which quickly solves performance problems for computing derived data.

if you want to use @computed with non-manually maintained dependencies, you should enable auto computed feature by setting 'autoComputed' to 'true' in the dev options.

Example​

class Shop {
@state
fruits = [];

@state
vegetables = [];

@computed(({ fruits, vegetables }: Shop) => [fruits, fruits])
get sum() {
return this.fruits.length + this.vegetables.length;
}
}

Parameters​

NameType
depsCallback(instance: any) => any[]

Returns​

fn

▸ (target, key, descriptor): any

Parameters​
NameType
targetobject
keystring
descriptorTypedPropertyDescriptor<any>
Returns​

any

Defined in​

packages/reactant-module/src/decorators/computed.ts:17