Websocket to ts

This commit is contained in:
Adria Navarro 2025-01-10 10:30:19 +01:00
parent bb18115585
commit e23be5acb8
1 changed files with 5 additions and 3 deletions

View File

@ -1,12 +1,14 @@
import { get } from "svelte/store" import { get } from "svelte/store"
import { createWebsocket } from "../../../utils" import { createWebsocket } from "../../../utils"
import { SocketEvent, GridSocketEvent } from "@budibase/shared-core" import { SocketEvent, GridSocketEvent } from "@budibase/shared-core"
import { Store } from "../stores"
import { UIDatasource } from "@budibase/types"
export const createGridWebsocket = context => { export const createGridWebsocket = (context: Store) => {
const { rows, datasource, users, focusedCellId, definition, API } = context const { rows, datasource, users, focusedCellId, definition, API } = context
const socket = createWebsocket("/socket/grid") const socket = createWebsocket("/socket/grid")
const connectToDatasource = datasource => { const connectToDatasource = (datasource: UIDatasource) => {
if (!socket.connected) { if (!socket.connected) {
return return
} }
@ -65,7 +67,7 @@ export const createGridWebsocket = context => {
GridSocketEvent.DatasourceChange, GridSocketEvent.DatasourceChange,
({ datasource: newDatasource }) => { ({ datasource: newDatasource }) => {
// Listen builder renames, as these aren't handled otherwise // Listen builder renames, as these aren't handled otherwise
if (newDatasource?.name !== get(definition).name) { if (newDatasource?.name !== get(definition)?.name) {
definition.set(newDatasource) definition.set(newDatasource)
} }
} }