dkrasner / Simpletalk

Apache License 2.0
53 stars 3 forks source link

browser interop #143

Closed dkrasner closed 1 year ago

dkrasner commented 1 year ago

Main Points

This PR adds proper browser part interop to the environment.

The browser part now has srcdoc property which is set as the underlying iframe's srcdoc attribute. And the window.message API allows for communication between the two.

The browser has a forward command which sends messages to the iframe.contentWindow (ie the srcdoc window). There the underlying running "app" can do whatever it needs with the message.

On the other hand the underlying srcdoc "app" can use the window.top.sendMessage api to send messages to the browser part. This is handled by System as here.

there is an example which you can import.

There are a number of things to notice here. In particular those mentioned in issues #141 and #142

The main fundamental change the addition of a serialize=false argument to the dynamic property value getter. And you can see it's use here

We need this b/c otherwise the browser DOM parser will fail, stopping at the first </script> which just might be present in your srcdoc.

Similarly if you use a field part to write you srcdoc code *do not save it since it will not deserialize/parser property (again see #141).

dkrasner commented 1 year ago

@launeh ?