Fir is a toolkit comprised of a Go server library to render html templates and an alpinejs plugin to progressively add reactivity to a web page.
<aside> ⚠️ Experimental with possibility of breaking changes until v1 is reached
</aside>
Leave comments on this page(needs notion.so login) or in github issues.
On receiving user-interactions the fir server re-renders html templates and sends it over the wire where the fir client library selectively updates the changed areas.
When a user event is received by a Fir route, an array of html templates are rendered on the server and returned as an array of DOM events to the browser. The DOM events are consumed by the alpinejs plugin and dispatched within the DOM where listeners attached to DOM elements can use the DOM event to update the DOM. Lets unbundle to understand the core concepts:
Browser/Server → Event → OnEvent → pubsub.Event → subscription.C → renderDOMEvents → []dom.Event → Browser
Fir doesn’t know one user from another. It expects the user
string to be in the request.Context
to ensure a websocket session is unique per user. The below code snippet can be part of the authentication middleware.
// set by the app server
func setUserInContext(ctx context.Context, user string) context.Context {
return context.WithValue(ctx, fir.UserKey, user)
}
// internally in Fir library
func getUserFromContext(ctx context.Context) *string {
user, ok := ctx.Value(fir.UserKey).(string)
if !ok {
return nil
}
return &user
}