pull/10302/head
Dominic Gannaway 3 years ago
parent 24b90a500a
commit b799868c3c

@ -8,7 +8,10 @@ import {
updating_derived, updating_derived,
UNINITIALIZED, UNINITIALIZED,
mutable_source, mutable_source,
batch_inspect batch_inspect,
current_derived_property_access,
effect_active_and_not_render_effect,
is_primitive_or_function_or_state_object
} from './runtime.js'; } from './runtime.js';
import { import {
array_prototype, array_prototype,
@ -197,6 +200,15 @@ const state_proxy_handler = {
} }
if (s !== undefined) { if (s !== undefined) {
if (
current_derived_property_access !== null &&
current_derived_property_access.v === receiver &&
(effect_active_and_not_render_effect() || updating_derived) &&
is_primitive_or_function_or_state_object(s.v)
) {
current_derived_property_access.v = s.v;
current_derived_property_access.p.push(prop);
}
const value = get(s); const value = get(s);
return value === UNINITIALIZED ? undefined : value; return value === UNINITIALIZED ? undefined : value;
} }

@ -62,7 +62,7 @@ let current_queued_effects = [];
/** /**
* @type {import('./types.js').DerivedPropertyAccess | null} * @type {import('./types.js').DerivedPropertyAccess | null}
*/ */
let current_derived_property_access = null; export let current_derived_property_access = null;
/** @type {Array<() => void>} */ /** @type {Array<() => void>} */
let current_queued_tasks = []; let current_queued_tasks = [];
@ -1452,7 +1452,7 @@ function proxify_object(signal, value, handler, path) {
/** /**
* @param {any} value * @param {any} value
*/ */
function is_primitive_or_function_or_state_object(value) { export function is_primitive_or_function_or_state_object(value) {
const type = typeof value; const type = typeof value;
return ( return (
value == null || value == null ||
@ -1505,7 +1505,7 @@ function create_derived_proxy(signal, derived_value) {
if (current_derived_property_access !== null) { if (current_derived_property_access !== null) {
capture_derived_property_access(current_derived_property_access); capture_derived_property_access(current_derived_property_access);
} else { } else {
current_derived_property_access = { s: signal, p: new_path }; current_derived_property_access = { s: signal, p: new_path, v: value };
} }
} }
if (should_proxy_derived_value(value)) { if (should_proxy_derived_value(value)) {
@ -1614,7 +1614,7 @@ export function effect_active() {
/** /**
* @returns {boolean} * @returns {boolean}
*/ */
function effect_active_and_not_render_effect() { export function effect_active_and_not_render_effect() {
return current_effect ? (current_effect.f & (MANAGED | RENDER_EFFECT)) === 0 : false; return current_effect ? (current_effect.f & (MANAGED | RENDER_EFFECT)) === 0 : false;
} }

@ -130,6 +130,7 @@ export type ComputationSignal<V = unknown> = {
export type DerivedPropertyAccess = { export type DerivedPropertyAccess = {
s: ComputationSignal; s: ComputationSignal;
p: Array<string | symbol>; p: Array<string | symbol>;
v: any;
}; };
export type Signal<V = unknown> = SourceSignal<V> | ComputationSignal<V>; export type Signal<V = unknown> = SourceSignal<V> | ComputationSignal<V>;

Loading…
Cancel
Save