app v7.0.2 Release Notes
Release Date: 2020-06-28 // over 3 years ago-
Hello there,
I'm thrilled to release version 7 of go-app.This version is focused on internal improvements that improve code quality and maintainability. Unfortunately, those improvements bring a few small changes in the API, which is why there is a version bump.
What is new?
๐ป Context that is bound to a UI element lifecycle. The context can be used with functions that accept context.Context. Contexts are canceled when the UI element they are bound with is dismounted. It is passed in Mounter and Navigator interfaces, and event handlers.
โ TestMatch: testing api to unit test specific UI element:
tree := app.Div().Body( app.H2().Body( app.Text("foo"), ), app.P().Body( app.Text("bar"), ), )// Testing root:err := app.TestMatch(tree, app.TestUIDescriptor{ Path: TestPath(), Expected: app.Div(), })// OK =\> err == nil// Testing h2:err := app.TestMatch(tree, app.TestUIDescriptor{ Path: TestPath(0), Expected: app.H3(), })// KO =\> err != nil because we ask h2 to match with h3// Testing text from p:err = app.TestMatch(tree, app.TestUIDescriptor{ Path: TestPath(1, 0), Expected: app.Text("bar"), })// OK =\> err == nil
๐ Support for
aria
HTML element property: Fix #419app.Div(). Aria("foo", "bar"). Text("foobar")
0๏ธโฃ A default logger can be set
๐ go-app PWA can now be deployed a GitHub Page with the help of GenerateStaticWebsite function:
package mainimport ( "fmt""github.com/maxence-charriere/go-app/v7/pkg/app")func main() { err := app.GenerateStaticWebsite("DST\_DIR", &app.Handler{ Name: "Github Pages Hello", Title: "Github Pages Hello", Resources: app.GitHubPages("goapp-github-pages"), }) if err != nil { fmt.Println(err) return } fmt.Println("static website generated") }
It generates files that can directly be dropped into a GitHub repository to serve the PWA.
๐ See live example: https://maxence-charriere.github.io/goapp-github-pages/๐ Support for
robots.txt
: A robots file is now served by the Handler when/web/robots.txt
exists๐จ Internal code refactored to be more maintainable
Serving static resources can now be customized by implementing the ResourceProvider interface
How to migrate from v6 to v7
go-app v7 mainly introduced internal improvements. Despite trying to keep the API the same as v6, those changes resulted in API minor modifications that break compatibility.
Here is a guide on how to adapt v6 code to make it work with v7.
Imports
Go
import
instructions using v6:import ( "github.com/maxence-charriere/go-app/v6/pkg/app")
must be changed to v7:
import ( "github.com/maxence-charriere/go-app/v7/pkg/app")
http.Handler
๐
RootDir
field has been removed.
0๏ธโฃ Handler now uses theResources
field to define where app resources and static resources are located. This has a default value that is retro compatible with local static resources. If static resources are located on a remote bucket, use the following:app.Handler{ Resources: app.RemoteBucket("BUCKET\_URL"), }
๐
UseMinimalDefaultStyles
field has been removed.
go-app now use CSS styles that only apply to the loading screen and context menus. The former default styles have been removed since they could conflict with some CSS frameworks.Component interfaces
โก๏ธ Some interfaces to deals with the lifecycle of components have been modified to take a context as the first argument. Component with methods that satisfies the following interfaces must be updated:
- Mounter :
OnMount()
becomeOnMount(ctx app.Context)
- Navigator :
OnNav(u *url.URL)
becomeOnNav(ctx app.Context u *url.URL)
Event handlers
EventHandler function signature has been also modified to take a context as the first argument:
func(src app.Value, e app.Event)
becomefunc(ctx app.Context, e app.Event)
Source is now accessed from the context:
// Event handler that retrieve input value when onchange is fired:func (c \*myCompo) OnChange(ctx app.Context, e app.Event) { v := ctx.JSSrc().Get("value") }
- Mounter :