Skip to content

Manage your events

Each gtag can declare its own methods, but those which are binded on Tag js events, are called events.

Calling an event will produce a re-rendering of the app !

Theses events's methods can be declared as sync, async or async generator.

Declaring your method/events

Consider this gtag component :

class App(GTag):
    def init(self):
        self.rows=[]
    def build(self):
        return Tag.div(
            Tag.button( "reload", onclick=self.bind.clickMe() ),
            Table(self.rows)
        )
    ...

The 3 following declarations are valid :

A sync method

    def clickMe(self):
        self.rows = [...]

The UI will wait the call.

A async method

    async def clickMe(self):
        self.rows = await fetch()

The UI will await the call. (TODO: COMPLETE HERE)

A async generator method

    async def clickMe(self):
        self.rows = []
        yield
        self.rows = await fetch()

The UI will await the call. But it will produce two rendering consecutivly. (TODO: COMPLETE HERE)

Start a method/event at start

Sometimes, it can be useful to start a process at the start of the GUI (ie: fetching data on the internet)

app=App()
app.run( start=app.clickMe() )

(TODO: COMPLETE HERE)