Skip to content

Commit 9c0dc71

Browse files
committed
Fix calculator example build by removing obsolete files and adding codegen workarounds
Changes: - Remove obsolete calculator.go and helpers.go (functionality moved to calculator.gx) - Remove duplicate console/log declarations from main.go (now in generated code) - Update app.gx to use make(chan CalculatorState, 10) instead of NewCalculatorStateChannel() - Add automated patching to build.sh to work around codegen issues: * Fix stateChannel references in closures (should use c.StateChannel) * Initialize state channel with default value in NewApp() - Update build.sh with proper wasm_exec.js fallback logic The calculator now builds successfully with all state management handled through channels.
1 parent e81026f commit 9c0dc71

5 files changed

Lines changed: 22 additions & 133 deletions

File tree

examples/calculator/app.gx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
func App() (Component) {
4-
stateChannel := NewCalculatorStateChannel()
4+
stateChannel := make(chan CalculatorState, 10)
55

66
Div(Class("app-container")) {
77
H1 {

examples/calculator/build.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,29 @@ cd ../..
99
go run ./cmd/guix generate -p examples/calculator
1010
cd examples/calculator
1111

12+
# Patch generated files to workaround codegen issues
13+
echo "Patching generated code..."
14+
# Fix stateChannel references in calculator_gen.go
15+
sed -i 's/handleNumber(stateChannel,/handleNumber(c.StateChannel,/g' calculator_gen.go
16+
sed -i 's/handleOperator(stateChannel,/handleOperator(c.StateChannel,/g' calculator_gen.go
17+
sed -i 's/handleClear(stateChannel)/handleClear(c.StateChannel)/g' calculator_gen.go
18+
sed -i 's/handleEquals(stateChannel,/handleEquals(c.StateChannel,/g' calculator_gen.go
19+
20+
# Initialize the state channel with initial value in app_gen.go
21+
sed -i '/c.stateChannel = make(chan CalculatorState, 10)/a\ c.stateChannel <- CalculatorState{Display: "0", PreviousValue: 0, Operator: "", WaitingForOperand: false}' app_gen.go
22+
1223
# Copy wasm_exec.js
1324
echo "Copying wasm_exec.js..."
14-
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
25+
GOROOT="$(go env GOROOT)"
26+
# Try lib/wasm first (Go 1.24+), then misc/wasm (older versions)
27+
if [ -f "$GOROOT/lib/wasm/wasm_exec.js" ]; then
28+
cp "$GOROOT/lib/wasm/wasm_exec.js" .
29+
elif [ -f "$GOROOT/misc/wasm/wasm_exec.js" ]; then
30+
cp "$GOROOT/misc/wasm/wasm_exec.js" .
31+
else
32+
echo "wasm_exec.js not found in GOROOT, downloading from GitHub"
33+
curl -o wasm_exec.js https://raw.githubusercontent.com/golang/go/go1.25.0/lib/wasm/wasm_exec.js
34+
fi
1535

1636
# Build WASM
1737
echo "Building WASM..."

examples/calculator/calculator.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/calculator/helpers.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

examples/calculator/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44
package main
55

66
import (
7-
"syscall/js"
8-
97
"github.com/gaarutyunov/guix/pkg/runtime"
108
)
119

12-
var console = js.Global().Get("console")
13-
14-
func log(args ...interface{}) {
15-
console.Call("log", args...)
16-
}
17-
1810
func main() {
1911
log("MAIN: Starting calculator example")
2012

0 commit comments

Comments
 (0)