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

Add document_body and document_element to gloo_utils #160

Closed
jplatte opened this issue Oct 25, 2021 · 1 comment · Fixed by #161
Closed

Add document_body and document_element to gloo_utils #160

jplatte opened this issue Oct 25, 2021 · 1 comment · Fixed by #161

Comments

@jplatte
Copy link
Contributor

jplatte commented Oct 25, 2021

Summary

I would like to propose addition of document_body() and document_element() helper functions to gloo-utils.

Motivation

So projects wanting to access document.documentElement and document.body don't have to write their own helper functions calling the web_sys functions + unwrapping.

Detailed Explanation

pub fn document_body() -> HtmlElement {
    document().body().expect_throw("Can't find document body")
}

pub fn document_element() -> Element {
    document().document_element().expect_throw("Can't find document element")
}

Drawbacks, Rationale, and Alternatives

Drawbacks: -

Alternatives: -

Rationale / prior art: I have these helpers in caniuse.rs' code base: https://github.com/jplatte/caniuse.rs/blob/21cae646a489bec4537e6628492c1669a89221fb/src/util.rs#L15-L21

Unresolved Questions

-

@ranile
Copy link
Collaborator

ranile commented Oct 26, 2021

I'd rename document_body to just body since it pulls the body element. That way it will be consistent with other functions.

I don't see why we shouldn't add those. If you want to PR those, feel free to.

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

Successfully merging a pull request may close this issue.

2 participants