Skip to content

HTML DOM Representation #42

Open
Open

Description

@DavePearce

(@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.

Activity

  1. DavePearce commented on Aug 23, 2019

    @DavePearce
    MemberAuthor

    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

  2. DavePearce commented on Aug 23, 2019

    @DavePearce
    MemberAuthor

    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.

  3. altmattr commented on Aug 23, 2019

    @altmattr
  4. DavePearce commented on Aug 23, 2019

    @DavePearce
    MemberAuthor

    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.

  5. altmattr commented on Aug 23, 2019

    @altmattr
  6. DavePearce commented on Aug 23, 2019

    @DavePearce
    MemberAuthor

    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 :(

  7. DavePearce commented on Aug 23, 2019

    @DavePearce
    MemberAuthor

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

  8. altmattr commented on Aug 23, 2019

    @altmattr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions