### Installing y-supabase Dependency with npm Source: https://github.com/alexdunmow/y-supabase/blob/main/README.md This command installs the `y-supabase` package as a dependency in your project using npm, making it available for use in your application. ```bash npm install --save y-supabase ``` -------------------------------- ### Initializing Y.Doc and SupabaseProvider in TypeScript Source: https://github.com/alexdunmow/y-supabase/blob/main/README.md This snippet demonstrates how to create a new Y.Doc instance and then initialize the SupabaseProvider. It connects the Y.Doc to Supabase using specified channel, table, and column names for real-time synchronization. ```typescript const yDoc = new Y.Doc() const provider = new SupabaseProvider(yDoc, supabase, { channel: note.id, id: note.id, tableName: "notes", columnName: "document" }) ``` -------------------------------- ### Handling SupabaseProvider Events in TypeScript Source: https://github.com/alexdunmow/y-supabase/blob/main/README.md This snippet demonstrates how to attach event listeners to the `SupabaseProvider` instance to react to various real-time updates and connection status changes. It covers events like `message`, `awareness`, `save`, `status`, `connect`, `error`, `disconnect`, `synced`, and `sync`, providing callbacks for each. ```typescript provider.on('message', (update) => { console.log('Received real-time update:', update); }); provider.on('awareness', (awarenessUpdate) => { console.log('Received awareness update:', awarenessUpdate); }); // version is local to the provider only, not a true version number provider.on('save', (version) => { console.log('Document saved to database with version:', version); }); provider.on('status', (status) => { console.log('Connection status update:', status); }); provider.on('connect', (providerInstance) => { console.log('Connected:', providerInstance); }); provider.on('error', (providerInstance) => { console.error('Error:', providerInstance); }); provider.on('disconnect', (providerInstance) => { console.log('Disconnected:', providerInstance); }); provider.on('synced', (state) => { console.log('Synced with state:', state); }); provider.on('sync', (state) => { console.log('Sync event with state:', state); }); ``` -------------------------------- ### Configuring SupabaseProvider with Optional resyncInterval in TypeScript Source: https://github.com/alexdunmow/y-supabase/blob/main/README.md This code illustrates the full configuration options for the SupabaseProvider, including the optional `resyncInterval` parameter. This parameter controls the frequency of complete document resynchronization with Supabase, defaulting to 5 seconds if not specified. ```typescript const provider = new SupabaseProvider(yDoc, supabase, { channel: note.id, id: note.id, tableName: "notes", columnName: "document", resyncInterval?: number | false; // Default: 5000 (5 seconds) }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.