Skip to main content

foundation-utils.reactive

Home > @genesislcap/foundation-utils > reactive

reactive() function

This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Converts a plain object to a reactive, observable object.

Signature:

export declare function reactive<T>(object: T, deep?: boolean): T;

Parameters

Parameter

Type

Description

object

T

The object to make reactive.

deep

boolean

(Optional) Indicates whether to deeply convert the object.

Returns:

T

The converted object.

Example 1

An array or reactive items.

this.todos = todosResponse.map((t) => reactive(t));

Example 2

Add item.

add(description: string) {
this.splice(this.todos.length, 0, reactive({ description, done: false }));
}

Example 3

Remove item.

remove(todo: Todo) {
const index = this.todos.indexOf(todo);
index !== -1 && this.splice(index, 1);
}