Spaces:
Runtime error
Runtime error
File size: 776 Bytes
6a839c1 423b87b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// @ts-nocheck
import type { Others } from "@liveblocks/client";
import { onDestroy } from "svelte";
import type { Writable } from "svelte/store";
import { writable } from "svelte/store";
import { useRoom } from "./useRoom";
/**
* Works similarly to `liveblocks-react` useOthers
* https://liveblocks.io/docs/api-reference/liveblocks-react#useOthers
*
* The main difference is that it returns a Svelte store:
* const others = useOthers()
* console.log($others.value)
* {#each [...$others] as other}
* ...
*/
export function useOthers(): Writable<Others> {
const room = useRoom();
const others = writable<Others>();
const unsubscribe = room.subscribe("others", (newOthers) => {
others.set(newOthers);
});
onDestroy(unsubscribe);
return others;
}
|