yznts/kyoto
关于
使用 Go 构建异步 HTML 组件
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
kyoto
Go server side frontend framework
import "github.com/yznts/kyoto/v3"
Kyoto is a library for creating fast, server side frontend avoiding vanilla templating downsides.
It tries to address complexities in frontend domain like responsibility separation, components structure, asynchronous load and hassle-free dynamic layout updates. These issues are common for frontends written with Go.
The library provides you with primitives for pages and components creation, state and rendering management, dynamic layout updates (with client configuration), utility functions and asynchronous components out of the box. Still, it bundles with minimal dependencies and tries to utilize built-ins as much as possible.
You would probably want to opt out from this library in few cases, like, if you're not ready for drastic API changes between major version, you want to develop SPA/PWA and/or complex client-side logic, or you're just feeling OK with your current setup. Please, don't compare kyoto with a popular JS libraries like React, Vue or Svelte. I know you will have such a desire, but most likely you will be wrong. Use cases and underlying principles are just too different.
If you want to get an idea of what a typical static component would look like, here's some sample code. It's very ascetic and simplistic, as we don't want to overload you with implementation details. Markup is also not included here (it's just a well-known `html/template`).
// State is declared separately from component itself
type ComponentState struct {
// We're providing component with some abilities here
component.Universal // This component uses universal state, that can be (un)marshalled with both server and client
// Actual component state is just struct fields
Foo string
Bar string
}
// Component is a function, that returns configured state.
// To be able to provide additional arguments to the component on initialization,
// you have to wrap component with additional function that will handle args and return actual component.
// Until then, you may keep component declaration as-is.
func Component(ctx *component.Context) component.State {
// Initialize state here.
// As far as component.Universal provided in declaration,
// we're implementing component.State interface.
state := &ComponentState{}
// Do whatever you want with a state
state.Foo = "foo"
state.Bar = "bar"
// Done
return state
}
For details, please check the library index to explore available sub-packages and https://pkg.go.dev for Go'ish documentation style.
探索相关项目
加载中…