Skip to content

Commit

Permalink
feat(client): allow unsubscribing the "once" call
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoBechtel committed Jul 13, 2023
1 parent 3babdd6 commit 0fca516
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/docs/docs/guide/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const unsubscribe = db.get('friends/status').on((data, meta) => {

## once

`once: (callback: (data: any, meta: Meta) => void) => void`
`once: (callback: (data: any, meta: Meta) => void) => Unsubscriber`

Same as `on`, but only receives data once.
It will automatically unsubscribe from server after receiving data.
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type ChainReference<Schema extends SchemaDefinition = any> = {
) => ChainReference<Schema>;
delete: () => void;
on: (callback: (data: Schema | null, meta?: Meta) => void) => Unsubscriber;
once: (callback: (data: Schema | null, meta?: Meta) => void) => void;
once: (callback: (data: Schema | null, meta?: Meta) => void) => Unsubscriber;
};

export type ClientHooks = {
Expand Down Expand Up @@ -373,7 +373,7 @@ export function SocketDBClient<Schema extends RootSchemaDefinition = any>({
});
},
once(callback) {
subscriptions.update.subscribe(
return subscriptions.update.subscribe(
normalizedPath,
function listener(data) {
// maybe should use subscribe {once: true} ?
Expand Down

0 comments on commit 0fca516

Please sign in to comment.