type Message = {content: string, username: string}
// in backend
const getMessagesLive = makeLiveServerFn(
"QUERY",
(input: Input) => (subscriberContext, publisherContext) => {
return {
publishTo: "/dashboard/:serverId",
updateWhen: subscriberContext.params.serverId === publisherContext.params.serverId
&& publisherContext.messageId === "post-message",
data: getMessages(input, subscriberContext)
}
}
)
const postMessageLive = makeLiveServerFn(
"MUTATE",
(input: Message) => {
return {
publishTo: "/dashboard/:serverId",
mutate: await createMessage(input, sub),
messageId: "post-message"
}
}
)
// Then on frontend you could do something like
const MessageBoard = () => {
const {data: messages, error} = useLiveData(getTodos)
// get's published whenever any user subscribed to /todos route
}
type Message = {content: string, username: string}
// in backend
const getMessagesLive = makeLiveServerFn(
"QUERY",
(input: Input) => (subscriberContext, publisherContext) => {
return {
publishTo: "/dashboard/:serverId",
updateWhen: subscriberContext.params.serverId === publisherContext.params.serverId
&& publisherContext.messageId === "post-message",
data: getMessages(input, subscriberContext)
}
}
)
const postMessageLive = makeLiveServerFn(
"MUTATE",
(input: Message) => {
return {
publishTo: "/dashboard/:serverId",
mutate: await createMessage(input, sub),
messageId: "post-message"
}
}
)
// Then on frontend you could do something like
const MessageBoard = () => {
const {data: messages, error} = useLiveData(getTodos)
// get's published whenever any user subscribed to /todos route
}