7 Commits

Author SHA1 Message Date
4c022b13ac Remove accidentally committed binary
All checks were successful
CI / build (pull_request) Successful in 29s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 17:19:04 +01:00
a580df7b72 Add decrement button to counter example
All checks were successful
CI / build (pull_request) Successful in 29s
Address review feedback to include a decrement button that
demonstrates reactive updates in both directions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 17:18:49 +01:00
0f924d8e8a Add counter example demonstrating signals
All checks were successful
CI / build (pull_request) Successful in 28s
Basic example showing:
- Creating a signal with NewSignal
- Reading value with Get()
- Writing value with Set()
- Button click handler
- Reactive text that updates when signal changes

Closes #4

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:59:54 +01:00
2db0628a89 Add host server setup guide
All checks were successful
CI / build (pull_request) Successful in 27s
CI / build (push) Successful in 27s
Documents the host package covering:
- Basic server setup with code example
- Directory structure for WASM apps
- Static file serving and SPA fallback
- WASM MIME type configuration
- Automatic gzip compression
- Development vs production considerations

Closes #3

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:50:55 +01:00
5aa1498ab7 Add hello world example
All checks were successful
CI / build (pull_request) Successful in 39s
CI / build (push) Successful in 27s
Minimal Iris application demonstrating:
- Signal creation with NewSignal
- Reactive text rendering with TextFromFunction
- Auto-incrementing counter to show reactivity

Closes #2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:44:59 +01:00
260f46e814 Fix README clarity issues from code review
All checks were successful
CI / build (pull_request) Successful in 27s
CI / build (push) Successful in 29s
- Add explicit mkdir -p public before wasm_exec.js copy
- Specify to save app code as main.go
- Specify to save server code as server.go

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:40:21 +01:00
46aa4cc502 Add README quickstart section
All checks were successful
CI / build (pull_request) Successful in 28s
Provides a complete getting-started guide covering prerequisites,
app creation, HTML host setup, build commands, and running the app.

Closes #1

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:36:12 +01:00
4 changed files with 300 additions and 0 deletions

112
README.md Normal file
View File

@@ -0,0 +1,112 @@
# Iris
WASM reactive UI framework for Go.
## Quickstart
Get from zero to a running app in under 5 minutes.
### Prerequisites
- Go 1.23 or later
### Project setup
```bash
mkdir -p public
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./public/
```
### Create your app
Save this as `main.go`:
```go
//go:build js && wasm
package main
import (
"fmt"
"git.flowmade.one/flowmade-one/iris/reactive"
"git.flowmade.one/flowmade-one/iris/ui"
)
func main() {
count := reactive.NewSignal(0)
view := ui.NewView()
view.Child(ui.TextFromFunction(func() string {
return fmt.Sprintf("Count: %d", count.Get())
}))
view.Child(ui.Button(func() {
count.Set(count.Get() + 1)
}, ui.TextFromString("Click me")))
ui.NewApp(view)
// Keep the program running
select {}
}
```
### Create the HTML host
Create `public/index.html`:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Iris App</title>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("app.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
</head>
<body></body>
</html>
```
### Build
```bash
GOOS=js GOARCH=wasm go build -o public/app.wasm ./main.go
```
### Run
Save this as `server.go`:
```go
package main
import (
"net/http"
"git.flowmade.one/flowmade-one/iris/host"
)
func main() {
server := host.New("public", "index.html")
http.ListenAndServe(":8080", server)
}
```
Then run:
```bash
go run server.go
```
### Expected output
Open http://localhost:8080 in your browser. You should see:
- A "Count: 0" text
- A "Click me" button
- Clicking the button increments the count reactively

36
examples/counter/main.go Normal file
View File

@@ -0,0 +1,36 @@
//go:build js && wasm
package main
import (
"fmt"
"git.flowmade.one/flowmade-one/iris/reactive"
"git.flowmade.one/flowmade-one/iris/ui"
)
func main() {
// Create a signal with initial value 0
count := reactive.NewSignal(0)
view := ui.NewView()
// Reactive text that updates when count changes
view.Child(ui.TextFromFunction(func() string {
return fmt.Sprintf("Count: %d", count.Get())
}))
// Button that increments the count on click
view.Child(ui.Button(func() {
count.Set(count.Get() + 1)
}, ui.TextFromString("Increment")))
// Button that decrements the count on click
view.Child(ui.Button(func() {
count.Set(count.Get() - 1)
}, ui.TextFromString("Decrement")))
ui.NewApp(view)
select {}
}

32
examples/hello/main.go Normal file
View File

@@ -0,0 +1,32 @@
//go:build js && wasm
package main
import (
"fmt"
"time"
"git.flowmade.one/flowmade-one/iris/reactive"
"git.flowmade.one/flowmade-one/iris/ui"
)
func main() {
count := reactive.NewSignal(0)
// Increment count every second to show reactivity
go func() {
for {
time.Sleep(time.Second)
count.Set(count.Get() + 1)
}
}()
view := ui.NewView()
view.Child(ui.TextFromFunction(func() string {
return fmt.Sprintf("Hello, Iris! Count: %d", count.Get())
}))
ui.NewApp(view)
select {}
}

120
host/README.md Normal file
View File

@@ -0,0 +1,120 @@
# Host Package
Static file server optimized for serving Iris WASM applications.
## Basic Setup
```go
package main
import (
"log"
"net/http"
"git.flowmade.one/flowmade-one/iris/host"
)
func main() {
server := host.New("public", "index.html")
log.Println("Server running on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", server))
}
```
## Directory Structure
```
myapp/
├── server.go # Server code (above)
└── public/
├── index.html # Entry point
├── app.wasm # Compiled WASM binary
└── wasm_exec.js # Go WASM runtime
```
## Serving Static Files
The server serves files from the specified public directory. Any request path maps directly to files:
- `/``public/index.html`
- `/app.wasm``public/app.wasm`
- `/styles.css``public/styles.css`
**SPA Fallback**: Unknown paths and directories fall back to `index.html`, enabling client-side routing.
## WASM MIME Types
The server automatically sets correct MIME types for all common file types:
| Extension | MIME Type |
|-----------|-----------|
| `.wasm` | `application/wasm` |
| `.html` | `text/html; charset=utf-8` |
| `.js` | `application/javascript` |
| `.css` | `text/css` |
| `.json` | `application/json` |
| `.svg` | `image/svg+xml` |
This ensures browsers load WASM files correctly without manual configuration.
## Compression
Gzip compression is automatically applied to compressible content types when the client supports it:
- HTML, CSS, JavaScript
- JSON
- WASM binaries
- SVG images
Binary assets (PNG, JPEG, etc.) are served uncompressed since they're already compressed.
## Development vs Production
### Development
```go
func main() {
server := host.New("public", "index.html")
http.ListenAndServe(":8080", server)
}
```
Run with:
```bash
go run server.go
```
### Production
For production, compile the server and run as a binary:
```bash
go build -o server ./server.go
./server
```
Consider adding:
- TLS termination (via reverse proxy or `http.ListenAndServeTLS`)
- Environment-based port configuration
- Graceful shutdown handling
Example with TLS:
```go
func main() {
server := host.New("public", "index.html")
log.Fatal(http.ListenAndServeTLS(":443", "cert.pem", "key.pem", server))
}
```
Example with reverse proxy (nginx):
```nginx
server {
listen 443 ssl;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
}
}
```