zserge / lorca

Build cross-platform modern desktop apps in Go + HTML5
MIT License
8.04k stars 535 forks source link

make Eval script work after reload #16

Closed yaodingyd closed 5 years ago

yaodingyd commented 6 years ago

Currently Eval would not survive after a reload. I add Page.addScriptToEvaluateOnNewDocument in ui.Eval to make sure Eval script can run after reload.

I think extra document will be needed since script will be run before document ready, so user should wrap their own code inside a DOMContentLoaded

zserge commented 6 years ago

I don't think this is the right solution to a problem.

Eval() is for one-shot non-persistent operations (e.g. change something in the UI as a reaction to some event in the app).

Bind() on the other hand is persistent and the binding remains after page reload. The right solution I think would be to bind a Go function, call that from window.onload and do Eval() there if you need.

yaodingyd commented 6 years ago

So every persistent UI change will look something like this?

ui.Bind(ui.Eval(`/*DOM manipulation code*/`))