Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: better store subscriptions #12277

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
Rich-Harris committed Jul 3, 2024
commit e97f0cf7b88f0d203b3886b1538d4b02e8f6374a
19 changes: 6 additions & 13 deletions packages/svelte/src/internal/client/reactivity/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@ import { mutable_source, set } from './sources.js';
* @returns {V}
*/
export function store_get(store, store_name, stores) {
/** @type {StoreReferencesContainer[''] | undefined} */
let entry = stores[store_name];
const is_new = entry === undefined;

if (is_new) {
entry = {
store: null,
value: mutable_source(UNINITIALIZED),
unsubscribe: noop
};
stores[store_name] = entry;
}
const entry = (stores[store_name] ??= {
store: null,
value: mutable_source(UNINITIALIZED),
unsubscribe: noop
});

if (is_new || entry.store !== store) {
if (entry.store !== store) {
entry.unsubscribe();
entry.store = store ?? null;
entry.unsubscribe = connect_store_to_signal(store, entry.value);
Expand Down