Skip to content

Releases: maxence-charriere/go-app

Version 7

28 Jun 18:23
Compare
Choose a tag to compare

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 #419

    app.Div().
        Aria("foo", "bar").
        Text("foobar")
  • A default logger can be set

  • go-app PWA can now be deployed a GitHub Page with the help of GenerateStaticWebsite function:

    package main
    
    import (
        "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.
    Handler now uses the Resources 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() become OnMount(ctx app.Context)
  • Navigator: OnNav(u *url.URL) become OnNav(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) become func(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")
    }

Fix manual Navigation

23 Jun 22:01
07a2a38
Compare
Choose a tag to compare

Summary

  • Navigate does not trigger a page reload anymore when called manually.

Thanks to @jwmach1 and @walgenbach for reporting this.

Fix component update bug

10 Jun 11:31
36efa81
Compare
Choose a tag to compare

Summary

  • Fixes a bug that always triggered a component replacement when its root was another component

Crash Fixe and Indirect function exported

10 Jun 00:23
53f03d1
Compare
Choose a tag to compare

Summary

  • Fixes a crash that occurred when a component was the root of another component
  • Indirect is now exported
  • The Updatable interface has been removed: code will compile but OnUpdate functions are not called anymore. This is removed because I felt it complicate components life cycle and was buggy.

Clean body and fix hash navigation

15 May 11:16
157b232
Compare
Choose a tag to compare

Hello,
I'm glad to release the version 6.5.0.

Clean body

go-app now provides the function CleanBody. This is to remove extra elements in the body that might be added by third-party libraries.

While building an app, I ran into a problem where Amazon advertisements where popping into the screen when navigating fast to other pages. The problem was that Amazon is loading a script to display their ads. When the loaded code does not find the ad container (when a component is dismounted), it inserts the ads directly in the body.

This is to prevent this kind of behavior from third-party libraries.

Bug Fixes

Some code has been refactored and hash navigation (eg. http://my.domain/hello#Input) now works properly.

Improve stability

08 May 08:41
67f1d8b
Compare
Choose a tag to compare

Hello there,
This version brings some stability improvements:

  • nil values are now ignored when they are put in an element body
  • Component updates are now properly skipped when a component is dismounted or when the update is done from the same pointer
  • OnNav from the Navigator interface is now propagated to all components

v6.4.0

05 May 06:18
bb870e2
Compare
Choose a tag to compare

Hello,
Here is the v6.4.0. This release brings a couple of modifications:

  • OnUpdate: You can now listen for a component update by implementing the Updatable interface.
    type myCompo struct {
        app.Compo
    }
    
    func (c *myCompo) OnUptdate() {
        // Component has been updated...
    }
  • app.Text() now takes an interface{} that is stringified to render a text node
  • OnLoad event handler has been added to supported HTML elements
  • Non self closing HTML elements now have a Text(v interface{}) helper method that sets the element body to a single text node:
    app.H1().Text("hello")
    
    // Same as:
    
    app.H1().Body(
        app.Text("hello"),
    )
  • LocalStorage and SessionStorage encryption has been removed in order to let user decide how they manage those storages. Adding encryption added an overhead in size that made storage filled faster while the maximum size is 10MB

Dismounter fix and other

20 Apr 06:29
43815bc
Compare
Choose a tag to compare

Hello,
Here is a minor update that addresses reported issues:

  • OnDismount method is now called when the Dismounter interface is implemented
  • Added the JSValue function that allows getting the underlying syscall/js value from a javascript value
    // JSValue returns the underlying syscall/js value of the given Javascript
    // value.
    func JSValue(v Value) js.Value {
        return jsval(v)
    }
  • HTTP handler can now be set to use a light version of app.css. The light version does not provide default styling for HTML elements. It can be enabled by setting the UseMinimalDefaultStyles to true:
    h := app.Handler{
        UseMinimalDefaultStyles: true,
    }

Thanks to @jwmach1, @voldyman, and @ruanwenfeng for reporting issues and submitting PR.

PWA env

07 Apr 10:21
e32126e
Compare
Choose a tag to compare

Hello there.

This version allows setting environment variables to the HTTP Handler that are passed to the WebAssembly app.

How to use?

Set the environment variables in the app.Handler:

app.Handler{
    Env: app.Environment {
        "CUSTOM_FOO", "foo",
        "CUSTOM_BAR", "bar",
    },
}

Then in the WebAssembly app, retrieve it by calling Getenv:

foo := app.Getenv("CUSTOM_FOO")

Bug fixes/minor changes

  • Child node parent is now properly set when a node is added during an update
  • Browser storage have a memory implementation in non-wasm architecture
  • A Dispatcher type has been added to describe a function that is executed on the UI goroutine
  • Readme has been updated to show contributors

Thanks

thead tag and bug fix

05 Apr 07:32
0206841
Compare
Choose a tag to compare

Hello there.

This release contains the following changes:

  • Support for <thead> tag
  • Javascript files are now included at the end of the body in order to avoid concurrent access to the page loader

Thanks to @jwmach1 for reporting those issues.