Skip to content

Commit

Permalink
feat(rescript-intersection-observer): add new observer with option
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Aug 12, 2022
1 parent 798ef40 commit 51f692a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/dev/dev__intersection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions examples/dev/dev__intersection.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ let observer = Intersection.Observer.new(entries => {
}
})

let observerWithOptions = Intersection.Observer.newWithOption(entries => {
switch entries {
| [head] => {
head->Intersection.ObserverEntry.intersectionRatio->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.x->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.width->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.height->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.top->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.right->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.bottom->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.left->Js.log
head->Intersection.ObserverEntry.boundingClientRect->DOMRect.toJson->Js.log
head->Intersection.ObserverEntry.time->Js.log
head->Intersection.ObserverEntry.isVisible->Js.log
head->Intersection.ObserverEntry.target->Js.log
let rect = DOMRect.rect(~x=1.0, ~y=2.0, ())
rect->DOMRect.fromRect->Js.log
}
| _ => ()
}
}, Intersection.ObserverInit.new(~rootMargin="0px", ()))

observerWithOptions->Intersection.Observer.observe(htmlDom())

observerWithOptions->Intersection.Observer.unobserve(htmlDom())

observer->Intersection.Observer.observe(htmlDom())

observer->Intersection.Observer.unobserve(htmlDom())
Expand Down
3 changes: 3 additions & 0 deletions rescript-intersection-observer/src/Intersection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions rescript-intersection-observer/src/Intersection.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,27 @@ module ObserverEntry = {
external time: t => float = "time"
}

module ObserverInit = {
type t

@obj
external new: (
~root: Dom.element=?,
~rootMargin: string=?,
~thresholds: array<float>=?,
unit,
) => t = ""
}

module Observer = {
type t = Dom.intersectionObserver

@new
external new: (array<ObserverEntry.t> => unit) => t = "IntersectionObserver"

@new
external newWithOption: (array<ObserverEntry.t> => unit, ObserverInit.t) => t =
"IntersectionObserver"
// properties

// TODO: intersectionObserver.root return Dom.element or Dom.document
Expand Down

0 comments on commit 51f692a

Please sign in to comment.