Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML DOM Representation #42

Open
DavePearce opened this issue Aug 22, 2019 · 8 comments
Open

HTML DOM Representation #42

DavePearce opened this issue Aug 22, 2019 · 8 comments

Comments

@DavePearce
Copy link
Member

DavePearce commented Aug 22, 2019

(@altmattr --- this may also be of interest to you)

My initial efforts to represent the DOM in Whiley have provided some interesting observations. Firstly, we need some way to interact natively with the DOM (see #41). Secondly, the DOM has an inbuilt concept of a union type. For example, here is an abridged version of the Node interface:

public type Node is &{
    int nodeType,
    js_string nodeName,
    (null | Element) parent,
    Node[] childNodes,
    ...
}

From this, we can see two interesting things: js_string and null | Element.

Both of these pose interesting questions. At this stage, I've just modelled a js_string using an int because this give me a sensible (if not slightly broken) translation. Likewise, at this stage, the union type null | Element is modelled correctly because we are not using tagged unions. However, as soon as we employ tagged unions (which is my current plan) this will break.

Perhaps one other interesting thing is that there is a clear notion of inheritance between the Node interface and the Element interface. Currently, Whiley provides no support for capturing this.

@DavePearce
Copy link
Member Author

One possible solution here is to support a concept of an untagged or raw union. This is something I've thought about before. The syntax would be: (null || Element). In principle, this should only happen between record types which have a common initial sequence. But, that doesn't work for (null || Element) anyways. Hmmmmmmmmmm

@DavePearce
Copy link
Member Author

The other option, of course, is just to accept that we have to have a shim around the DOM to enable interaction from Whiley. That could work, but would add some overhead. Potentially in many cases this could be circumvented.

@altmattr
Copy link

altmattr commented Aug 23, 2019 via email

@DavePearce
Copy link
Member Author

Well, yes, but then in Elm land you are stuck to a specific model. Whereas if we can represent the actual DOM somehow, then we can interact with it and choose our own models.

Still, even having a shim around the DOM ... I'm not sure how that would work. I can do it using the virtual DOM approach of Elm, but I don't know how to enable more direct access.

@altmattr
Copy link

altmattr commented Aug 23, 2019 via email

@DavePearce
Copy link
Member Author

Ok, maybe I could figure this out using a native type. Maybe I should have a go and see if I can do that. Currently fighting with various minor problems in the compiler in an effort to get an actual single-page app working :(

@DavePearce
Copy link
Member Author

Also, I thought you were against the Elm approach??

@altmattr
Copy link

altmattr commented Aug 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants