Skip to content

Commit 4e836b6

Browse files
committed
Merge branch 'improved_types'
2 parents 40e4b6f + 6cd9a71 commit 4e836b6

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
1212
## main
1313

14+
15+
#### :boom: Breaking Change
16+
17+
- Corrected return type of `getPropertyValue` for CSS style attributes (it's nullable and now returns an option).
18+
19+
#### :bug: Bug Fix
20+
21+
- Widened input type of `Window.getComputedStyle`, allowing subclasses of Element (such as HtmlElement).
22+
1423
# 0.9.1
1524

1625
#### :bug: Bug Fix

lib/js/tests/Webapi/Dom/Webapi__Dom__Window__test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ window.focus();
3333

3434
window.getComputedStyle(el);
3535

36+
window.getComputedStyle(el);
37+
38+
window.getComputedStyle(el, "hover");
39+
3640
window.getComputedStyle(el, "hover");
3741

3842
window.getSelection();
@@ -83,7 +87,10 @@ window.onload = (function (param) {
8387
console.log("load");
8488
});
8589

90+
var htmlEl = el;
91+
8692
exports.el = el;
93+
exports.htmlEl = htmlEl;
8794
exports.$$event = $$event;
8895
exports.handleClick = handleClick;
8996
exports.idleId = idleId;

src/Webapi/Dom/Webapi__Dom__CssStyleDeclaration.res

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ type cssRule /* TODO: Move to Webapi__Dom */
77
@get external parentRule: t => cssRule = "parentRule"
88

99
@send external getPropertyPriority: (t, string) => string = "getPropertyPriority"
10-
@send external getPropertyValue: (t, string) => string = "getPropertyValue"
10+
@send @return(nullable)
11+
external getPropertyValue: (t, string) => option<string> = "getPropertyValue"
1112
@send external item: (t, int) => string = "item"
1213
@send external removeProperty: (t, string) => string = "removeProperty"
1314
@send external setProperty: (t, string, string, string) => unit = "setProperty"
@@ -135,4 +136,4 @@ type cssRule /* TODO: Move to Webapi__Dom */
135136
@get external widows: t => string = "widows"
136137
@get external width: t => string = "width"
137138
@get external wordSpacing: t => string = "wordSpacing"
138-
@get external zIndex: t => string = "zIndex"
139+
@get external zIndex: t => string = "zIndex"

src/Webapi/Dom/Webapi__Dom__Window.res

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ module Impl = (
7878
@send external close: t_window => unit = "close"
7979
@send external confirm: (t_window, string) => bool = "confirm"
8080
@send external focus: t_window => unit = "focus"
81-
@send external getComputedStyle: (t_window, Dom.element) => Dom.cssStyleDeclaration = "getComputedStyle"
81+
@send
82+
external getComputedStyle: (t_window, Dom.element_like<'a>) => Dom.cssStyleDeclaration =
83+
"getComputedStyle"
8284
@send
8385
external getComputedStyleWithPseudoElement: (
8486
t_window,
85-
Dom.element,
87+
Dom.element_like<'a>,
8688
string,
8789
) => Dom.cssStyleDeclaration = "getComputedStyle"
8890
@send @return(nullable) external getSelection: t_window => option<Dom.selection> = "getSelection"

tests/Webapi/Dom/Webapi__Dom__Window__test.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
open Webapi.Dom
22

33
let el = document->Document.createElement("strong")
4+
let htmlEl = el->Element.unsafeAsHtmlElement
45
let event = document->Document.createEvent("my-event")
56
let handleClick = _ => print_endline("asd")
67

@@ -53,7 +54,9 @@ Window.close(window)
5354
let _ = window->Window.confirm("is ok?")
5455
Window.focus(window)
5556
let _ = window->Window.getComputedStyle(el)
57+
let _ = window->Window.getComputedStyle(htmlEl)
5658
let _ = window->Window.getComputedStyleWithPseudoElement(el, "hover")
59+
let _ = window->Window.getComputedStyleWithPseudoElement(htmlEl, "hover")
5760
let _ = Window.getSelection(window)
5861
let _ = window->Window.matchMedia("max-height: 400")
5962
let _ = window->Window.moveBy(10, -10)

0 commit comments

Comments
 (0)