Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/draganm/go-reactor
Golang Implementation of Server-Side Reactive Framework
https://github.com/draganm/go-reactor
Last synced: about 2 months ago
JSON representation
Golang Implementation of Server-Side Reactive Framework
- Host: GitHub
- URL: https://github.com/draganm/go-reactor
- Owner: draganm
- License: other
- Created: 2016-12-06T23:12:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-27T11:59:06.000Z (5 months ago)
- Last Synced: 2024-07-27T13:05:49.908Z (5 months ago)
- Language: Go
- Homepage:
- Size: 24.6 MB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-reactor
Framework for writing completely reactive web applications.## Hello-World
Simple one page hello world program that counts number of clicks:
```go
package mainimport (
"fmt"
"sync""github.com/draganm/go-reactor"
)func main() {
r := reactor.New()
r.AddScreen("/", indexScreenFactory)
r.Serve(":8080")
}func indexScreenFactory(ctx reactor.ScreenContext) reactor.Screen {
return &indexScreen{
ctx: ctx,
}
}var indexScreenTemplate = reactor.MustParseDisplayModel(`
You've clicked hello world: times
`)type indexScreen struct {
sync.Mutex
ctx reactor.ScreenContext
clickCounter int
}func (i *indexScreen) Mount() {
i.clickCounter = 0
i.render()
}func (i *indexScreen) render() {
ui := indexScreenTemplate.DeepCopy()
ui.SetElementText("count", fmt.Sprintf("%d", i.clickCounter))
i.ctx.UpdateScreen(&reactor.DisplayUpdate{
Model: ui,
})
}func (i *indexScreen) OnUserEvent(evt *reactor.UserEvent) {
i.Lock()
defer i.Unlock()if evt.ElementID == "hw" {
i.clickCounter++
i.render()
}
}func (i *indexScreen) Unmount() {}
```
## Updating dependencies
```sh
npm install
gulp
cd public
go generate
cd ..
```