Migrating
Move an app to WebGo v1.0.0, from WebGo v0.1.0, or from go-app v11 and WebGo v0.0.5.
Coming from WebGo v0.1.0, only
From v0.1.0
applies: the
page
and
data
packages moved into
app
. Coming from go-app v11 or WebGo v0.0.5, read the other sections first, then that one.
Since v0.1.0, WebGo contains go-app v11.0.5's
pkg/app
as its own
app
package. Components, routing, the context, state and actions keep their names and signatures. What changes is the import path, the inline-style setters, the handler, the update flow and a few rendering details.
Each section shows the code before and after. The compiler finds the syntax changes; the behaviour changes are listed under Behaviour changes without syntax changes and Service worker and updates .
ยง1 From v0.1.0
The
page
and
data
packages are deleted. Screens, the shell and models are
app
types now, next to
Compo
, and a screen is a component that the engine routes to. Before:
settings
:=
page
.
NewPage
[
AppState
]
(
"/settings"
)
.
WithLayout
(
&
settingsLayout
{
}
)
.
WithModel
(
model
)
base
,
err
:=
page
.
NewBase
(
&
shellLayout
{
}
,
shellModel
,
[
]
page
.
Screen
{
home
,
settings
}
)
for
_
,
route
:=
range
[
]
string
{
"/"
,
"/settings"
}
{
app
.
Route
(
route
,
func
(
)
app
.
Composer
{
return
base
}
)
}
After:
app
.
Serve
(
func
(
)
*
app
.
Shell
[
ShellState
]
{
settings
:=
app
.
NewScreen
[
AppState
]
(
"/settings"
)
.
WithLayout
(
&
settingsLayout
{
}
)
.
WithModel
(
model
)
.
WithLoader
(
fetchSettings
)
shell
,
err
:=
app
.
NewShell
(
&
shellLayout
{
}
,
shellModel
,
home
,
settings
)
if
err
!=
nil
{
panic
(
err
)
}
return
shell
}
)
-
page.NewPagebecomesapp.NewScreen, andpage.Page[T]becomesapp.Screen[T]. -
page.NewBase(layout, model, []page.Screen{...})becomesapp.NewShell(layout, model, screens...). Build it inside the function passed toapp.Serve, which registers every screen's route. Build the screens there too: the server calls the function once per request. -
data.NewViewModelanddata.ViewModel[T]becomeapp.NewModelandapp.Model[T].data.Action[T], returned byLoad, becomesapp.Change[T].ApplyandSetkeep their signatures. -
page.Layout[T]becomesapp.Layout[T], with the same four methods.Drawtakes*app.Model[T].page.Screenbecomesapp.Routed: a component with aRoute(). -
Delete every
OnActioncall. EverySetnow fires the action named after the model's key, so styles bound to it follow on their own. -
Screens have no
Content(),OnMount/OnDismountreturning a screen, orMounted(). A screen draws withRenderlike any component. -
BasePath()is gone. The shell reads the mount prefix fromGOAPP_ROOT_PREFIX, whichapp.Handlersets fromResources; read it withapp.Getenvif you need it. -
If you faked loading with a flag set in
OnMount, move the fetch intoWithLoader, or intoOnLoadon any component. ItsLoading()shows until it returns, and itsError(err)when it fails. See OnLoad .
go get github.com/Toms223/WebGo@v1.0.0
go mod tidy