-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Golang example ? #26
Comments
The concept I am working with is to use htmx to update the frontend with html or Json Data. typically html is pushed, and api wanted to try pushing new templates at runtime |
Thanks! I'll attempt sketching a super simple kanban. Starting with the shape of the type Item = {
title: string;
details: string;
};
type Lane = {
title: string;
items: Item[];
};
type Project = {
title: string;
lanes: Lane[];
};
declare const sb: { data: Project }; Note, I've normalized the shape. It can be denormalized to have everything InitializationConsidering that only one project would be open at a time, the main reactive sb.data = {
title: '' /* placeholder title */,
lanes: []
} A project is fetched from the server on connecting. It can be directly set onto sb.data = {
title: 'The Board',
lanes: [
{
title: 'To Do',
items: [
{ title: '...', details: '...' },
],
},
{
title: 'Done',
items: []
},
],
}; Propagating updatesThere'll be a couple of functions to update the data, a few examples: function addItem(item: Item, laneTitle: string);
function shiftItem(itemTitle: string, toLane: string);
function deleteItem(itemTitle: string); These function will do just one thing and that is update the reactive object, function addItem(item: Item, laneTitle: string) {
const lane = data.lanes.find(({ title }) => title === laneTitle)
lane?.items.push(item)
} This way, they can be used for both:
For example: addItemButton.addEventListener('click', () => {
const item = getNewItem() // Read from input elements
const laneTitle = getLaneTitle() // Read from input element/parent
// UI to reactive object
addItem(item, lane)
// UI to socket
socket.send(
JSON.stringify({
message: 'add-item',
data: {item, laneTitle}
})
)
})
socket.addEventListener('message', (event) => {
const data = JSON.parse(event.data)
// socket to reactive object (by extention UI)
if (data.message = 'add-item') {
const {item, laneTitle} = data.data
addItem(item, laneTitle)
}
}) In the above example, changes applied to the reactive object propagate to the ComplicationsA couple of complications, if required. Propagate from reactive object to socketThe reactive object can be made the center of updates such that any changes to sb.watch('lanes.0.items', () => { /* do something */}) The issue here is that since For instance a
It'd be highly imprudent to transmit all of those changes, depending on the And so it's better to handle UI to socket propagation in the in the UI event Optimistic updatesThe example above uses optimistic updates. UI is updated (by updating the If the update fails on the server side, then a message will be regarding this Failure can be handled in multiple ways, for instance sending the old state Denormalizing
|
@18alantom
The new docs are really good.
I am keen to try to do an example that integrates a golang backend with Strawberry.
Could you possible outline how the API should work between the 2 layers ?
I am keen to see how the state between the 2 layers are synergistic. My plan is for all mutations to go to backend , and somehow update the json on the frontend when it changes. SSE or web sockets…
I was thinking of a nice simple example like a kanban that has projects and items and tags . A tag is the kanban lane.
If you want a different example just let me know also.
The text was updated successfully, but these errors were encountered: