pull/12985/head
Rich Harris 2 years ago
parent 5805970188
commit b243921353

@ -118,7 +118,7 @@ export function proxy(value, parent = null, prev) {
// create a source, but only if it's an own property and not a prototype property
if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) {
s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata), true);
s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata), null);
sources.set(prop, s);
}
@ -170,7 +170,7 @@ export function proxy(value, parent = null, prev) {
(current_effect !== null && (!has || get_descriptor(target, prop)?.writable))
) {
if (s === undefined) {
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED, true);
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED, null);
sources.set(prop, s);
}

@ -1,4 +1,4 @@
/** @import { Derived, Effect, Source, Value } from '#client' */
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
import { DEV } from 'esm-env';
import {
current_component_context,
@ -34,11 +34,11 @@ let inspect_effects = new Set();
/**
* @template V
* @param {V} v
* @param {boolean} [skip_derived_source]
* @param {Reaction | null} [owner]
* @returns {Source<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function source(v, skip_derived_source = false) {
export function source(v, owner = current_reaction) {
var source = {
f: 0, // TODO ideally we could skip this altogether, but it causes type errors
v,
@ -46,25 +46,27 @@ export function source(v, skip_derived_source = false) {
equals,
version: 0
};
if (!skip_derived_source && current_reaction !== null && (current_reaction.f & DERIVED) !== 0) {
if (owner !== null && (owner.f & DERIVED) !== 0) {
if (derived_sources === null) {
set_derived_sources([source]);
} else {
derived_sources.push(source);
}
}
return source;
}
/**
* @template V
* @param {V} initial_value
* @param {boolean} [skip_derived_source]
* @param {Reaction | null} [owner]
* @returns {Source<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value, skip_derived_source) {
const s = source(initial_value, skip_derived_source);
export function mutable_source(initial_value, owner) {
const s = source(initial_value, owner);
s.equals = safe_equals;
// bind the signal to the component context, in case we need to

@ -19,7 +19,7 @@ import { mutable_source, set } from './sources.js';
export function store_get(store, store_name, stores) {
const entry = (stores[store_name] ??= {
store: null,
source: mutable_source(undefined, true),
source: mutable_source(undefined, null),
unsubscribe: noop
});

Loading…
Cancel
Save