Skip to content

peek

peek<T, K>(target, key): T[K]

Defined in: aberdeen.ts:3246

Executes a function or retrieves a value without creating subscriptions in the current reactive scope, and returns its result.

This is useful when you need to access reactive data inside a reactive scope (like A) but do not want changes to that specific data to trigger a re-execute of the scope.

Note: You may also use unproxy to get to the raw underlying data structure, which can be used to similar effect.

T extends object

K extends string | number | symbol

T

Either a function to execute, or an object (which may also be an Array or a Map) to index.

K

Optional key/index to use when target is an object.

T[K]

The result of the function call, or the value at target[key] when target is an object or target.get(key) when it’s a Map.

Peeking within observer

const $data = A.proxy({ a: 1, b: 2 });
A(() => {
// re-executes only when $data.a changes, because $data.b is peeked.
const b = A.peek(() => $data.b);
console.log(`A is ${$data.a}, B was ${b} when A changed.`);
});
$data.b = 3; // Does not trigger console.log
$data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")

peek<K, V>(target, key): V

Defined in: aberdeen.ts:3247

Executes a function or retrieves a value without creating subscriptions in the current reactive scope, and returns its result.

This is useful when you need to access reactive data inside a reactive scope (like A) but do not want changes to that specific data to trigger a re-execute of the scope.

Note: You may also use unproxy to get to the raw underlying data structure, which can be used to similar effect.

K

V

Map<K, V>

Either a function to execute, or an object (which may also be an Array or a Map) to index.

K

Optional key/index to use when target is an object.

V

The result of the function call, or the value at target[key] when target is an object or target.get(key) when it’s a Map.

Peeking within observer

const $data = A.proxy({ a: 1, b: 2 });
A(() => {
// re-executes only when $data.a changes, because $data.b is peeked.
const b = A.peek(() => $data.b);
console.log(`A is ${$data.a}, B was ${b} when A changed.`);
});
$data.b = 3; // Does not trigger console.log
$data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")

peek<T>(target, key): T

Defined in: aberdeen.ts:3248

Executes a function or retrieves a value without creating subscriptions in the current reactive scope, and returns its result.

This is useful when you need to access reactive data inside a reactive scope (like A) but do not want changes to that specific data to trigger a re-execute of the scope.

Note: You may also use unproxy to get to the raw underlying data structure, which can be used to similar effect.

T

T[]

Either a function to execute, or an object (which may also be an Array or a Map) to index.

number

Optional key/index to use when target is an object.

T

The result of the function call, or the value at target[key] when target is an object or target.get(key) when it’s a Map.

Peeking within observer

const $data = A.proxy({ a: 1, b: 2 });
A(() => {
// re-executes only when $data.a changes, because $data.b is peeked.
const b = A.peek(() => $data.b);
console.log(`A is ${$data.a}, B was ${b} when A changed.`);
});
$data.b = 3; // Does not trigger console.log
$data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")

peek<T>(target): T

Defined in: aberdeen.ts:3249

Executes a function or retrieves a value without creating subscriptions in the current reactive scope, and returns its result.

This is useful when you need to access reactive data inside a reactive scope (like A) but do not want changes to that specific data to trigger a re-execute of the scope.

Note: You may also use unproxy to get to the raw underlying data structure, which can be used to similar effect.

T

() => T

Either a function to execute, or an object (which may also be an Array or a Map) to index.

T

The result of the function call, or the value at target[key] when target is an object or target.get(key) when it’s a Map.

Peeking within observer

const $data = A.proxy({ a: 1, b: 2 });
A(() => {
// re-executes only when $data.a changes, because $data.b is peeked.
const b = A.peek(() => $data.b);
console.log(`A is ${$data.a}, B was ${b} when A changed.`);
});
$data.b = 3; // Does not trigger console.log
$data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")