pull/12277/head
Rich Harris 2 years ago
parent e97f0cf7b8
commit 400f2ac558

@ -154,17 +154,12 @@ export function client_component(source, analysis, options) {
}
if (binding.kind === 'store_sub') {
if (store_setup.length === 0) {
store_setup.push(b.const('$$subscriptions', b.call('$.create_stores')));
store_setup.push(b.const('$$stores', b.call('$.setup_stores')));
}
// We're creating an arrow function that gets the store value which minifies better for two or more references
const store_reference = serialize_get_binding(b.id(name.slice(1)), instance_state);
const store_get = b.call(
'$.store_get',
store_reference,
b.literal(name),
b.id('$$subscriptions')
);
const store_get = b.call('$.store_get', store_reference, b.literal(name), b.id('$$stores'));
store_setup.push(
b.const(
binding.node,

@ -345,7 +345,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
}
if (state.scope.get(`$${left.name}`)?.kind === 'store_sub') {
return b.call('$.store_unsub', call, b.literal(`$${left.name}`), b.id('$$subscriptions'));
return b.call('$.store_unsub', call, b.literal(`$${left.name}`), b.id('$$stores'));
} else {
return call;
}

@ -2438,7 +2438,7 @@ export const template_visitors = {
b.thunk(b.sequence(indirect_dependencies))
);
const invalidate_store = store_to_invalidate
? b.call('$.invalidate_store', b.id('$$subscriptions'), b.literal(store_to_invalidate))
? b.call('$.invalidate_store', b.id('$$stores'), b.literal(store_to_invalidate))
: undefined;
const sequence = [];

@ -109,7 +109,7 @@ export {
update_prop
} from './reactivity/props.js';
export {
create_stores,
setup_stores,
invalidate_store,
mutate_store,
store_get,

@ -20,17 +20,17 @@ import { mutable_source, set } from './sources.js';
export function store_get(store, store_name, stores) {
const entry = (stores[store_name] ??= {
store: null,
value: mutable_source(UNINITIALIZED),
source: mutable_source(UNINITIALIZED),
unsubscribe: noop
});
if (entry.store !== store) {
entry.unsubscribe();
entry.store = store ?? null;
entry.unsubscribe = connect_store_to_signal(store, entry.value);
entry.unsubscribe = connect_store_to_signal(store, entry.source);
}
return get(entry.value);
return get(entry.source);
}
/**
@ -85,9 +85,9 @@ export function store_set(store, value) {
* @param {string} store_name
*/
export function invalidate_store(stores, store_name) {
const store = stores[store_name];
if (store.store) {
store_set(store.store, store.value.v);
var entry = stores[store_name];
if (entry.store !== null) {
store_set(entry.store, entry.source.v);
}
}
@ -95,7 +95,7 @@ export function invalidate_store(stores, store_name) {
* Unsubscribes from all auto-subscribed stores on destroy
* @returns {StoreReferencesContainer}
*/
export function create_stores() {
export function setup_stores() {
/** @type {StoreReferencesContainer} */
const stores = {};

@ -149,7 +149,7 @@ export type StoreReferencesContainer = Record<
{
store: Store<any> | null;
unsubscribe: Function;
value: Source<any>;
source: Source<any>;
}
>;

Loading…
Cancel
Save