Nodra is a concurrency-safe reactive state store for Go desktop applications. It provides Zustand-like ergonomics for MyGo apps while keeping state independent from the renderer and persistence backend.
go get github.com/yldm-tech/nodra@latestThe core package is github.com/yldm-tech/nodra. The optional inspector is github.com/yldm-tech/nodra/devtools, the optional bridge to web pages is github.com/yldm-tech/nodra/bridge, and the Edit menu integration for native UI is github.com/yldm-tech/nodra/nativeui.
package main
import (
"fmt"
"github.com/yldm-tech/nodra"
)
type State struct{ Count int }
func main() {
store := nodra.New(State{})
defer store.Close()
stop := store.Subscribe(func(s nodra.Snapshot[State]) {
fmt.Println(s.Value.Count)
})
defer stop()
_ = store.Update(func(s *State) { s.Count++ })
}- Versioned
Store[T]with synchronous subscriptions, bounded watches and read-only views. - Derived state, selectors, projections, field bindings and atomic transactions.
- Undo/redo history with grouping, filtering and payload budgets.
- JSON, versioned migration, encrypted, backup, journaled and conflict-checked persistence.
- Debounced, cancelable and queued async actions with progress, retries and metrics.
Scopefor ownership and shutdown ordering.- Optional MyGo invalidation helpers and a local authenticated DevTools inspector.
- A bridge that lets the web pages of a MyGo app follow a Store and change it through registered actions.
- Undo and Redo of the window's keys and Edit menu acting on a History, for MyGo native UI.
mygo.App.WhenReady(func() {
window := mygo.NewWindow(mygo.WindowOptions{Title: "Counter", Content: ui.View(view)})
// Redraws stop when the window closes. Keep the returned stop only to end them sooner: a defer here would end them as soon as WhenReady returns.
nodra.InvalidateSelector(store, window, func(s State) int {
return s.Count
})
})The integration targets MyGo v0.9.0. Keep temporary widget state in the view owner and commit only the edited field to the shared Store. See examples/mygo for a minimal native window.
history := nodra.Track(store, 100)
nativeui.InvalidateHistory(history, window) // redraw when Undo or Redo becomes possible
func (app *App) view(c *ui.Context) {
nativeui.UndoShortcuts(c, app.history) // Cmd+Z, Shift+Cmd+Z and the Edit menu
// ...
}The optional nativeui subpackage makes the window's Undo and Redo act on a History: the keys, and with MyGo 0.9.0 on macOS the Edit menu items, which are enabled only while history can act. A focused text input keeps its own undo. It is separate from the core so apps without native UI do not link MyGo's ui package.
Services and CLIs that share Stores but never open a window can build with -tags nodra_nomygo. It leaves out the *mygo.Window helpers (InvalidateTarget stays) so MyGo is not linked, and a CGO_ENABLED=0 Linux build is then a static executable. The tag applies to the whole build: nativeui, or any library that calls those helpers, does not compile with it, and bridge links MyGo again. See docs/support.md.
b := bridge.New(bridge.Options{})
stop, err := bridge.ExposeProjection(b, "counter", store, func(s State) PageState { return PageState{Count: s.Count} })
stopAdd, err := bridge.Handle(b, "counter/add", func(ctx context.Context, by int) error {
return store.Update(func(s *State) { s.Count += by })
})
b.Bind() // before App.Runimport { dispatch, remoteState } from "./nodra.js";
const counter = remoteState("counter"); // subscribe and getSnapshot fit useSyncExternalStore
await dispatch("counter/add", 1);The optional bridge subpackage makes a Store the one source of truth for native windows and web pages alike. Pages see only what the projection returns, receive a frame when it changes (coalesced into the latest only once about 1 MiB of frames waits for a slow page), and change state only through the actions Go registers. The JavaScript client in bridge/client has no dependencies. See docs/bridge.md and examples/web.
persistence := nodra.NewPersistence(store, nodra.FileStorage{Path: "state.json", Backup: true}, nodra.JSONCodec[State]{})
// A missing file is a first start. Stop on any other load error: autosave would overwrite the file.
if err := persistence.Load(ctx); err != nil && !errors.Is(err, fs.ErrNotExist) {
return err
}
writer, err := persistence.AutoSaveAsync(ctx, nodra.AsyncOptions{Debounce: 100 * time.Millisecond})
if err != nil {
return err
}
defer func() {
if err := writer.Close(shutdownCtx); err != nil {
// The store still owns the data: retry with persistence.Save using a fresh context, or report the error.
log.Printf("save state: %v", err)
}
}()Use VersionedJSONCodec, AESGCMCodec, Journal, Durable and WithConflictDetection when the application needs migrations, encryption or stronger file recovery guarantees. Details are in docs/architecture.md.
examples/workbench is the full Nodra + MyGo desktop project. It combines cloned state, local drafts, validated backup persistence, debounced and cancelable async search, async saves, scoped shutdown, native invalidation, English/Simplified Chinese localization and optional DevTools.
go run ./examples/workbench
go run ./examples/workbench -devtoolsThe smaller examples cover one integration at a time:
examples/basic: Store, subscriptions and batches.examples/mygo: native windows, invalidation, and Undo and Redo of the Edit menu.examples/persistent: migrations, backups and write-behind persistence.examples/devtools: local inspector and restoration.examples/web: a native window and a web page sharing one Store through the bridge.
inspector := devtools.New(devtools.Options{})
defer inspector.Close()
stop, err := devtools.Attach(inspector, "state", store.ReadOnly())
if err != nil {
panic(err)
}
defer stop()
url, _ := inspector.Listen()
fmt.Println(url)DevTools is read-only by default. AllowRestore explicitly enables typed JSON editing and snapshot restoration. See docs/devtools.md for redaction, limits, remote read-only mode and the JSON compatibility contract.
docs/public-api.md: root package API index.docs/bridge.md: web pages that follow a Store and dispatch actions.docs/architecture.md: ownership, concurrency and lifecycle semantics.docs/compatibility.md: v0.x to v1 compatibility policy.docs/support.md: supported Go, MyGo, OS, architecture and filesystem matrix.CONTRIBUTING.md: development and verification workflow.SECURITY.md: vulnerability reporting and sensitive-data policy.
go test ./...
go test -race ./...
go vet ./...
golangci-lint run ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...Nodra is one Go module: github.com/yldm-tech/nodra. The project requires Go 1.27.3 or newer and uses MyGo v0.9.0 for native integration.