Skip to content

Commit

Permalink
Release v0.11.2
Browse files Browse the repository at this point in the history
Export Store Interface type
  • Loading branch information
acurrieclark committed Nov 30, 2023
1 parent 5409c57 commit 4362294
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@onsetsoftware/automerge-svelte",
"description": "A svelte store and utilities for automerge",
"version": "0.11.1",
"version": "0.11.2",
"type": "module",
"scripts": {
"build": "tsc && vite build",
Expand Down
13 changes: 8 additions & 5 deletions src/automerge-derived-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
type Writable,
writable,
} from "svelte/store";
import type { AutomergeSvelteStore as AutomergeSvelteStoreType } from "./automerge-svelte-store.type";
import type { AutomergeSvelteStoreInterface } from "./automerge-svelte-store.type";

export class AutomergeDerivedStore<T, U>
implements Readable<T>, AutomergeSvelteStoreType<T>
implements Readable<T>, AutomergeSvelteStoreInterface<T>
{
#rootStore: AutomergeSvelteStore<U>;
#state: Writable<T>;
Expand All @@ -35,9 +35,12 @@ export class AutomergeDerivedStore<T, U>
}

public change = (callback: ChangeFn<T>, options: ChangeOptions<T> = {}) => {
const changed = this.#rootStore.change((doc) => {
callback(this.#discriminator(doc as U));
}, options as unknown as ChangeOptions<U>);
const changed = this.#rootStore.change(
(doc) => {
callback(this.#discriminator(doc as U));
},
options as unknown as ChangeOptions<U>,
);
return this.#discriminator(changed);
};

Expand Down
12 changes: 6 additions & 6 deletions src/automerge-svelte-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {
type Writable,
readable,
} from "svelte/store";
import type { AutomergeSvelteStore as AutomergeSvelteStoreType } from "./automerge-svelte-store.type";
import type { AutomergeSvelteStoreInterface } from "./automerge-svelte-store.type";

export class AutomergeSvelteStore<T>
implements Readable<T>, AutomergeSvelteStoreType<T>
implements Readable<T>, AutomergeSvelteStoreInterface<T>
{
#store: AutomergeStore<T> | null;
#state: Writable<T | null>;
#storeReady: Writable<boolean> = writable(false);
ready: Readable<boolean> = derived(this.#storeReady, (ready) => ready);

#subscribers: number = 0;
#unSubscriber: () => void = () => { };
#unSubscriber: () => void = () => {};

#unSubscribe: () => void = () => {
this.#unSubscriber();
Expand Down Expand Up @@ -60,7 +60,7 @@ export class AutomergeSvelteStore<T>
const unsubscribe =
this.#store?.subscribe((_, patchData) => {
set(patchData);
}) || (() => { });
}) || (() => {});

return () => {
unsubscribe();
Expand All @@ -87,7 +87,7 @@ export class AutomergeSvelteStore<T>
this.#subscribers--;
subscription();
};
}) as AutomergeSvelteStoreType<T>["subscribe"];
}) as AutomergeSvelteStoreInterface<T>["subscribe"];
}

swapStore(store: AutomergeStore<T>) {
Expand All @@ -111,7 +111,7 @@ export class AutomergeSvelteStore<T>
this.#unSubscriber =
this.#store?.subscribe((doc: Doc<T>) => {
this.#state.set(doc);
}) ?? (() => { });
}) ?? (() => {});
}

private setStoreReady() {
Expand Down
2 changes: 1 addition & 1 deletion src/automerge-svelte-store.type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ChangeFn, ChangeOptions, Doc } from "@automerge/automerge";
import type { Readable, Updater } from "svelte/store";

export interface AutomergeSvelteStore<T> {
export interface AutomergeSvelteStoreInterface<T> {
subscribe: Readable<T>["subscribe"];

change(callback: ChangeFn<T>, options?: ChangeOptions<T>): Doc<T>;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export { AutomergeDerivedStore } from "./automerge-derived-store";
export { AutomergeEntityStore } from "./automerge-entity-store";
export { AutomergeSvelteStore } from "./automerge-svelte-store";

export type { AutomergeSvelteStoreInterface } from "./automerge-svelte-store.type";

export type { EntityTitles } from "./automerge-entity-store";

0 comments on commit 4362294

Please sign in to comment.