Skip to content

Commit

Permalink
Merge branch 'v10' into node-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Sep 30, 2023
2 parents 7398a42 + 0b57931 commit 860a383
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 61 deletions.
18 changes: 6 additions & 12 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,20 @@ func internalURLChecker() func(string) bool {
}

func newClientBody(d Dispatcher) *htmlBody {
ctx, cancel := context.WithCancel(context.Background())
body := &htmlBody{
htmlElement: htmlElement{
tag: "body",
context: ctx,
contextCancel: cancel,
dispatcher: d,
jsElement: Window().Get("document").Get("body"),
tag: "body",
dispatcher: d,
jsElement: Window().Get("document").Get("body"),
},
}
body.setSelf(body)

ctx, cancel = context.WithCancel(context.Background())
content := &htmlDiv{
htmlElement: htmlElement{
tag: "div",
context: ctx,
contextCancel: cancel,
dispatcher: d,
jsElement: body.JSValue().firstElementChild(),
tag: "div",
dispatcher: d,
jsElement: body.JSValue().firstElementChild(),
},
}
content.setSelf(content)
Expand Down
11 changes: 0 additions & 11 deletions pkg/app/component.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"
"reflect"
"strings"
Expand Down Expand Up @@ -148,8 +147,6 @@ type resize struct{}
// Compo represents the base struct to use in order to build a component.
type Compo struct {
disp Dispatcher
ctx context.Context
ctxCancel func()
parentElem UI
root UI
this Composer
Expand All @@ -163,8 +160,6 @@ func (c *Compo) JSValue() Value {
// Mounted reports whether the component is mounted.
func (c *Compo) Mounted() bool {
return c.getDispatcher() != nil &&
c.ctx != nil &&
c.ctx.Err() == nil &&
c.root != nil && c.root.Mounted() &&
c.self() != nil
}
Expand Down Expand Up @@ -240,10 +235,6 @@ func (c *Compo) setSelf(v UI) {
c.this = nil
}

func (c *Compo) getContext() context.Context {
return c.ctx
}

func (c *Compo) getDispatcher() Dispatcher {
return c.disp
}
Expand Down Expand Up @@ -280,7 +271,6 @@ func (c *Compo) mount(d Dispatcher) error {
}

c.disp = d
c.ctx, c.ctxCancel = context.WithCancel(context.Background())

root := c.render()
if err := mount(d, root); err != nil {
Expand All @@ -306,7 +296,6 @@ func (c *Compo) mount(d Dispatcher) error {
}

func (c *Compo) dismount() {
c.ctxCancel()
dismount(c.root)

if dismounter, ok := c.this.(Dismounter); ok {
Expand Down
5 changes: 0 additions & 5 deletions pkg/app/condition.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"

"github.com/maxence-charriere/go-app/v9/pkg/errors"
Expand Down Expand Up @@ -106,10 +105,6 @@ func (c condition) self() UI {
func (c condition) setSelf(UI) {
}

func (c condition) getContext() context.Context {
return nil
}

func (c condition) getDispatcher() Dispatcher {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (ctx uiContext) cryptoKey() string {

func makeContext(src UI) Context {
return uiContext{
Context: src.getContext(),
Context: context.Background(),
src: src,
jsSrc: src.JSValue(),
appUpdateAvailable: appUpdateAvailable,
Expand Down
18 changes: 5 additions & 13 deletions pkg/app/html.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"
"reflect"
"strconv"
Expand Down Expand Up @@ -31,11 +30,9 @@ type htmlElement struct {
parent UI
children []UI

context context.Context
contextCancel func()
dispatcher Dispatcher
jsElement Value
this UI
dispatcher Dispatcher
jsElement Value
this UI
}

func (e *htmlElement) Tag() string {
Expand All @@ -51,7 +48,7 @@ func (e *htmlElement) JSValue() Value {
}

func (e *htmlElement) Mounted() bool {
return e.context != nil && e.context.Err() == nil
return e.jsElement != nil
}

func (e *htmlElement) name() string {
Expand All @@ -66,10 +63,6 @@ func (e *htmlElement) setSelf(v UI) {
e.this = v
}

func (e *htmlElement) getContext() context.Context {
return e.context
}

func (e *htmlElement) getDispatcher() Dispatcher {
return e.dispatcher
}
Expand Down Expand Up @@ -99,7 +92,6 @@ func (e *htmlElement) mount(d Dispatcher) error {
return errors.New("html element is already mounted").WithTag("tag", e.tag)
}

e.context, e.contextCancel = context.WithCancel(context.Background())
e.dispatcher = d

jsElement, err := Window().createElement(e.tag, e.xmlns)
Expand Down Expand Up @@ -138,7 +130,7 @@ func (e *htmlElement) dismount() {
eh.Dismount()
}

e.contextCancel()
e.jsElement = nil
}

func (e *htmlElement) canUpdateWith(v UI) bool {
Expand Down
2 changes: 0 additions & 2 deletions pkg/app/node.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"
"reflect"
"strings"
Expand All @@ -21,7 +20,6 @@ type UI interface {
name() string
self() UI
setSelf(UI)
getContext() context.Context
getDispatcher() Dispatcher
getAttributes() attributes
getEventHandlers() eventHandlers
Expand Down
2 changes: 0 additions & 2 deletions pkg/app/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func testMounted(t *testing.T, n UI) {
case *text, *raw:

default:
require.NoError(t, n.getContext().Err())
require.NotNil(t, n.self())
}

Expand All @@ -162,7 +161,6 @@ func testDismounted(t *testing.T, n UI) {
case *text, *raw:

default:
require.Error(t, n.getContext().Err())
require.Nil(t, n.self())
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/app/range.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"
"reflect"
"sort"
Expand Down Expand Up @@ -105,10 +104,6 @@ func (r rangeLoop) self() UI {
func (r rangeLoop) setSelf(UI) {
}

func (r rangeLoop) getContext() context.Context {
return nil
}

func (r rangeLoop) getDispatcher() Dispatcher {
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/app/raw.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"io"
"strings"

Expand Down Expand Up @@ -54,10 +53,6 @@ func (r *raw) self() UI {
func (r *raw) setSelf(UI) {
}

func (r *raw) getContext() context.Context {
return nil
}

func (r *raw) getDispatcher() Dispatcher {
return r.disp
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/app/text.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"context"
"fmt"
"html"
"io"
Expand Down Expand Up @@ -45,10 +44,6 @@ func (t *text) self() UI {
func (t *text) setSelf(n UI) {
}

func (t *text) getContext() context.Context {
return context.TODO()
}

func (t *text) getDispatcher() Dispatcher {
return t.disp
}
Expand Down

0 comments on commit 860a383

Please sign in to comment.