Documentation
¶
Overview ¶
Package devkit runs an island app from a script, with no agent in the loop, for development: Go tests drive it with a headless browser, and a program under cmd/ serves it to try widgets by hand.
The Kit is an http.Handler serving one page with the island. Every page open renders a fresh island and, when App.Script is set, starts the script on it; Start, Continue and Stop act on the page opened last. What the script reports with ui.notify, and how each run ends, goes to App.Report.
func main() {
kit, err := devkit.New(devkit.App{
Island: neui.Island{
Name: "board",
Template: func(slot gox.Comp) gox.Elem { return func(cur gox.Cursor) error { return cur.Comp(slot) } },
Library: func(l neui.Library) error {
return nekit.IslandRegisterForm(l)
},
},
Script: `ui.root.set(ui.form({fields: [{type: "text", label: "Name", name: "name"}]})); while (true) ui.notify(ui.draw())`,
})
if err != nil {
log.Fatal(err)
}
defer kit.Close()
log.Fatal(http.ListenAndServe(":8080", kit))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// Island is rendered as the page's only content; an empty Name becomes
// "island".
Island neui.Island
// Config limits the runs; zero fields take the defaults.
Config api.IslandConfig
// Files limits the workspace, such as the size of a file a form
// uploads; zero fields take the defaults.
Files api.FilesConfig
// Dir is the workspace directory; empty uses a temporary one that Close
// removes.
Dir string
// Script starts on every page open; empty starts nothing.
Script string
// Report receives what the runs report; nil prints it to stderr.
Report func(Report)
}
App is the island the Kit serves and how it runs.
type Kit ¶
type Kit struct {
// contains filtered or unexported fields
}
Kit serves the island page and runs scripts on it.
func (*Kit) Continue ¶
Continue queues code on the running app of the page opened last; interrupt drops the queue and stops the script that runs.
type Report ¶
type Report struct {
// Task is the run's id; 0 when a script failed to start.
Task uint
// Kind is "notify", "ok" or "error".
Kind string
// Data is the notification or the result.
Data json.RawMessage
// Meta is the notification's meta, such as its kind and script.
Meta map[string]any
// Err is the error the run ended or failed to start with.
Err error
}
Report is a notification or the end of a run.