factorapp / factor

Component based full stack web framework using Web Assembly for Go
https://factorapp.io
Apache License 2.0
60 stars 5 forks source link

Idea: prefetch data #20

Open arschles opened 6 years ago

arschles commented 6 years ago

It would be nice to pretty easily pre-fetch data from a server, or pre-compute data even if it's on a client. For example, if you're loading a TODO list, you could return an empty todo list in your wasm app, and then grab the TODOs from the server via an RPC call. Maybe a rough idea how it could work?

// Factor library code
type Prerenderer interface {
    func Prerender() (interface{}, error)
}

// Component code that a user writes
func (comp *MyComponent) Prerender() (interface{}, error) {
    todos, err := rpcClient.GetTODOs()
    if err != nil {
        return nil, err
    }
    return todos, nil
}

factor build and similar commands can generate code that calls Prerender on components that implement Prerenderer before they are rendered and replace the contents of the component with the data returned.

arschles commented 6 years ago

Related to #19

bketelsen commented 6 years ago

I think there is a vecty "OnMount" event we can use rather than creating a new interface.

bketelsen commented 6 years ago

Yes: https://github.com/gopherjs/vecty/blob/master/dom.go#L67