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

Simplify createDerivedStore in debug.derived.ts #1801

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
17 changes: 9 additions & 8 deletions frontend/src/lib/derived/debug.derived.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import {
type Writable,
} from "svelte/store";

const createDerivedStore = <T>(store: Writable<T>): Readable<T> =>
derived(store, (store) => store);
const createReadableStore = <T>(store: Writable<T>): Readable<T> => ({
subscribe: store.subscribe,
});

let addAccountStore: Readable<AddAccountStore>;
export const debugAddAccountStore = (store: Writable<AddAccountStore>) =>
(addAccountStore = createDerivedStore(store));
(addAccountStore = createReadableStore(store));

// Context stores might not be initialized when debugger is called.
// Therefore, we need to initialize them here.
Expand All @@ -45,14 +46,14 @@ let walletStore: Readable<WalletStore> = readable({
neurons: [],
});
export const debugSelectedAccountStore = (store: Writable<WalletStore>) =>
(walletStore = createDerivedStore(store));
(walletStore = createReadableStore(store));
let selectedProposalStore: Readable<SelectedProposalStore> = readable({
proposalId: undefined,
proposal: undefined,
});
export const debugSelectedProposalStore = (
store: Writable<SelectedProposalStore>
) => (selectedProposalStore = createDerivedStore(store));
) => (selectedProposalStore = createReadableStore(store));
let selectedCanisterStore: Readable<SelectCanisterDetailsStore> = readable({
info: undefined,
details: undefined,
Expand All @@ -62,21 +63,21 @@ let selectedCanisterStore: Readable<SelectCanisterDetailsStore> = readable({
});
export const debugSelectedCanisterStore = (
store: Writable<SelectCanisterDetailsStore>
) => (selectedCanisterStore = createDerivedStore(store));
) => (selectedCanisterStore = createReadableStore(store));
let selectedProjectStore: Readable<ProjectDetailStore> = readable({
summary: null,
swapCommitment: null,
});
export const debugSelectedProjectStore = (
store: Writable<ProjectDetailStore>
) => (selectedProjectStore = createDerivedStore(store));
) => (selectedProjectStore = createReadableStore(store));
let selectedSnsNeuronStore: Readable<SelectedSnsNeuronStore> = readable({
selected: undefined,
neuron: undefined,
});
export const debugSelectedSnsNeuronStore = (
store: Writable<SelectedSnsNeuronStore>
) => (selectedSnsNeuronStore = createDerivedStore(store));
) => (selectedSnsNeuronStore = createReadableStore(store));
const transactionsStore = writable<Transaction[] | undefined>(undefined);
export const debugTransactions = (transactions: Transaction[] | undefined) => {
transactionsStore.set(transactions);
Expand Down