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.NewPage becomes app.NewScreen , and page.Page[T] becomes app.Screen[T] .
  • page.NewBase(layout, model, []page.Screen{...}) becomes app.NewShell(layout, model, screens...) . Build it inside the function passed to app.Serve , which registers every screen's route. Build the screens there too: the server calls the function once per request.
  • data.NewViewModel and data.ViewModel[T] become app.NewModel and app.Model[T] . data.Action[T] , returned by Load , becomes app.Change[T] . Apply and Set keep their signatures.
  • page.Layout[T] becomes app.Layout[T] , with the same four methods. Draw takes *app.Model[T] . page.Screen becomes app.Routed : a component with a Route() .
  • Delete every OnAction call. Every Set now fires the action named after the model's key, so styles bound to it follow on their own.
  • Screens have no Content() , OnMount / OnDismount returning a screen, or Mounted() . A screen draws with Render like any component.
  • BasePath() is gone. The shell reads the mount prefix from GOAPP_ROOT_PREFIX , which app.Handler sets from Resources ; read it with app.Getenv if you need it.
  • If you faked loading with a flag set in OnMount , move the fetch into WithLoader , or into OnLoad on any component. Its Loading() shows until it returns, and its Error(err) when it fails. See OnLoad .
                  go get github.com/Toms223/WebGo@v1.0.0
go mod tidy
                
01