-
Notifications
You must be signed in to change notification settings - Fork 48
Make use of ocaml's type system #57
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
Open
pkel
wants to merge
5
commits into
OvermindDL1:master
Choose a base branch
from
pkel:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| type 'msg t = 'msg Vdom.t | ||
| type 'msg prop = 'msg Vdom.property | ||
|
|
||
| (* Nodes *) | ||
|
|
||
| val noNode : 'msg t | ||
| val text : string -> 'msg t | ||
|
|
||
| type 'msg createNode = ?key:string -> ?unique:string -> | ||
| 'msg prop list -> 'msg t list -> 'msg t | ||
|
|
||
| (* TODO: needed? *) | ||
| val node : ?namespace:string -> string -> 'msg createNode | ||
|
|
||
| val lazy1 : string -> ( unit -> 'msg t) -> 'msg t | ||
|
|
||
| (* HTML Elements *) | ||
|
|
||
| val br : 'msg prop list -> 'msg t | ||
|
|
||
| val br' : 'msg createNode | ||
| val div : 'msg createNode | ||
| val span : 'msg createNode | ||
| val p : 'msg createNode | ||
| val pre : 'msg createNode | ||
| val a : 'msg createNode | ||
| val section : 'msg createNode | ||
| val header : 'msg createNode | ||
| val footer : 'msg createNode | ||
| val h1 : 'msg createNode | ||
| val h2 : 'msg createNode | ||
| val h3 : 'msg createNode | ||
| val h4 : 'msg createNode | ||
| val h5 : 'msg createNode | ||
| val h6 : 'msg createNode | ||
| val i : 'msg createNode | ||
| val strong : 'msg createNode | ||
| val button : 'msg createNode | ||
| val input' : 'msg createNode | ||
| val textarea : 'msg createNode | ||
| val label : 'msg createNode | ||
| val ul : 'msg createNode | ||
| val ol : 'msg createNode | ||
| val li : 'msg createNode | ||
| val table : 'msg createNode | ||
| val thead : 'msg createNode | ||
| val tfoot : 'msg createNode | ||
| val tbody : 'msg createNode | ||
| val th : 'msg createNode | ||
| val tr : 'msg createNode | ||
| val td : 'msg createNode | ||
| val progress : 'msg createNode | ||
| val img : 'msg createNode | ||
| val select : 'msg createNode | ||
| val option' : 'msg createNode | ||
| val form : 'msg createNode | ||
| val nav : 'msg createNode | ||
| val main : 'msg createNode | ||
| val aside : 'msg createNode | ||
| val article : 'msg createNode | ||
| val details : 'msg createNode | ||
| val figcaption : 'msg createNode | ||
| val figure : 'msg createNode | ||
| val mark : 'msg createNode | ||
| val summary : 'msg createNode | ||
| val time : 'msg createNode | ||
|
|
||
| (* Properties *) | ||
|
|
||
| val noProp : 'msg prop | ||
| val id : string -> 'msg prop | ||
|
|
||
| (* `href` is actually an attribute, not a property, but need it here for Elm compat... *) | ||
| val href : string -> 'msg prop | ||
|
|
||
| (* `src` is actually an attribute, not a property, but need it here for Elm compat... *) | ||
| val src : string -> 'msg prop | ||
|
|
||
| val class' : string -> 'msg prop | ||
| (* val classList : (string * bool) list -> 'msg prop *) | ||
| val type' : string -> 'msg prop | ||
| val style : string -> string -> 'msg prop | ||
| val styles : (string * string) list -> 'msg prop | ||
| val placeholder : string -> 'msg prop | ||
| val autofocus : bool -> 'msg prop | ||
| val value : string -> 'msg prop | ||
| val name : string -> 'msg prop | ||
| val checked : bool -> 'msg prop | ||
| val for' : string -> 'msg prop | ||
| val hidden : bool -> 'msg prop | ||
| val target : string -> 'msg prop | ||
| val action : string -> 'msg prop | ||
| val method' : string -> 'msg prop | ||
|
|
||
| (* Events *) | ||
|
|
||
| (* TODO: should this be exposed? *) | ||
| val onCB : string -> string -> (Web.Node.event -> 'msg option) -> 'msg prop | ||
| val onMsg : string -> 'msg -> 'msg prop | ||
|
|
||
| val onInput : ?key:string -> (string -> 'msg) -> 'msg prop | ||
| val onChange : ?key:string -> (string -> 'msg) -> 'msg prop | ||
| val onClick : 'msg -> 'msg prop | ||
| val onDoubleClick : 'msg -> 'msg prop | ||
| val onBlur : 'msg -> 'msg prop | ||
| val onFocus : 'msg -> 'msg prop | ||
| val onCheck : ?key:string -> (bool -> 'msg) -> 'msg prop | ||
| val onMouseDown : 'msg -> 'msg prop | ||
| val onMouseUp : 'msg -> 'msg prop | ||
| val onMouseEnter : 'msg -> 'msg prop | ||
| val onMouseLeave : 'msg -> 'msg prop | ||
| val onMouseOver : 'msg -> 'msg prop | ||
| val onMouseOut : 'msg -> 'msg prop | ||
|
|
||
| module Attributes : sig | ||
| val max : string -> 'msg prop | ||
| val min : string -> 'msg prop | ||
| val step : string -> 'msg prop | ||
| val disabled : bool -> 'msg prop | ||
| val selected : bool -> 'msg prop | ||
| val acceptCharset : string -> 'msg prop | ||
| val rel : string -> 'msg prop | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| val focus : string -> 'a Tea_cmd.t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| (* https://github.com/Matt-Esch/virtual-dom/blob/master/docs/vnode.md *) | ||
|
|
||
| type 'msg applicationCallbacks = { | ||
| enqueue : 'msg -> unit; | ||
| } | ||
|
|
||
| (* Attributes are not properties *) | ||
| (* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes *) | ||
|
|
||
| type 'msg eventHandler = | ||
| | EventHandlerCallback of string * (Web.Node.event -> 'msg option) | ||
| | EventHandlerMsg of 'msg | ||
|
|
||
| type 'msg eventCache = | ||
| { handler : Web.Node.event_cb | ||
| ; cb : (Web.Node.event -> 'msg option) ref | ||
| } | ||
|
|
||
| type 'msg property = | ||
| | NoProp | ||
| | RawProp of string * string (* TODO: This last string needs to be made something more generic, maybe a function... *) | ||
| (* Attribute (namespace, key, value) *) | ||
| | Attribute of string * string * string | ||
| | Data of string * string | ||
| (* Event (name, userkey, callback) *) | ||
| | Event of string * 'msg eventHandler * 'msg eventCache option ref | ||
| (* | Event of string * (Web.Event.t -> 'msg) *) | ||
| | Style of (string * string) list | ||
|
|
||
| type 'msg properties = 'msg property list | ||
|
|
||
| type 'msg t = | ||
| | CommentNode of string | ||
| | Text of string | ||
| (* Node (namespace, tagName, key, unique, properties, children) *) | ||
| | Node of string * string * string * string * 'msg properties * 'msg t list | ||
| (* | ArrayNode of string * string * string * string * 'msg property array * 'msg t array *) | ||
| (* LazyGen (key, fnGenerator) *) | ||
| | LazyGen of string * (unit -> 'msg t) * 'msg t ref | ||
| (* Tagger (toString, toDom, toVNodes) *) | ||
| (* | Tagger of (unit -> string) * ('msg applicationCallbacks ref -> Web.Node.t -> Web.Node.t -> int -> 'msg t list -> Web.Node.t) * (unit -> 'msg t) *) | ||
| (* Tagger (tagger, vdom) *) | ||
| | Tagger of ('msg applicationCallbacks ref -> 'msg applicationCallbacks ref) * 'msg t | ||
| (* *) | ||
| (* | Tagger of (('a -> 'msg) -> 'a t -> 'msg t) *) | ||
| (* Custom (key, cbAdd, cbRemove, cbChange, properties, children) *) | ||
| (* | Custom of string * (unit -> Web.Node.t) * (Web.Node.t -> unit) * *) | ||
|
|
||
|
|
||
| (* Nodes *) | ||
|
|
||
| val noNode : 'msg t | ||
|
|
||
| val comment : string -> 'msg t | ||
|
|
||
| val text : string -> 'msg t | ||
|
|
||
| val fullnode : string -> string -> string -> string | ||
| -> 'msg properties -> 'msg t list -> 'msg t | ||
|
|
||
| val node : ?namespace:string -> string -> ?key:string -> ?unique:string | ||
| -> 'msg properties -> 'msg t list -> 'msg t | ||
|
|
||
| val lazyGen : string -> (unit -> 'msg t) -> 'msg t | ||
|
|
||
| (* Properties *) | ||
|
|
||
| val noProp : 'msg property | ||
|
|
||
| val prop : string -> string -> 'msg property | ||
|
|
||
| val onCB : string -> string -> (Web.Node.event -> 'msg option) -> | ||
| 'msg property | ||
|
|
||
| val onMsg : string -> 'msg -> 'msg property | ||
|
|
||
| val attribute : string -> string -> string -> 'msg property | ||
|
|
||
| val data : string -> string -> 'msg property | ||
|
|
||
| val style : string -> string -> 'msg property | ||
|
|
||
| val styles : (string * string) list -> 'msg property | ||
|
|
||
| (* Accessors *) | ||
|
|
||
| val renderToHtmlString : 'msg t -> string | ||
|
|
||
| (* Patching / Diffing *) | ||
|
|
||
| val eventHandler_Register : | ||
| 'msg applicationCallbacks ref -> | ||
| Web.Node.t -> | ||
| string -> | ||
| 'msg eventHandler -> | ||
| 'msg eventCache option | ||
|
|
||
| val eventHandler_Unregister : Web.Node.t -> string | ||
| -> 'msg eventCache option -> 'msg option | ||
|
|
||
|
|
||
| val patchVNodesIntoElement : 'msg applicationCallbacks ref -> | ||
| Web.Node.t -> 'msg t list -> 'msg t list -> 'msg t list | ||
|
|
||
| (* TODO: rename mapCallbacks *) | ||
| val wrapCallbacks : ('a -> 'b) -> 'b applicationCallbacks ref -> | ||
| 'a applicationCallbacks ref | ||
|
|
||
| val map : ('a -> 'b) -> 'a t -> 'b t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
n##remove : unit -> unitfrom typet. Ifremoveis meant to be an impure function which removes a node from the DOM, it's type should beval remove: t -> unit. A correct implemention would belet remove n = n##remove ().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh that was entirely a copy-paste munge! Good catch! ^.^
Hmm, I'm not even using this function it looks like, maybe it should not even exist...