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

[cssom] Allow passing a callback to window.getComputedStyle(…) #3579

Open
ExE-Boss opened this issue Jan 31, 2019 · 2 comments
Open

[cssom] Allow passing a callback to window.getComputedStyle(…) #3579

ExE-Boss opened this issue Jan 31, 2019 · 2 comments
Labels

Comments

@ExE-Boss
Copy link
Contributor

ExE-Boss commented Jan 31, 2019

https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle

Right now, window.getComputedStyle(…) is always executed synchronously.

By allowing the last parameter to be a callback, this function could be made asynchronous in a backwards compatible manner.

interface Window {
    getComputedStyle(elt: Element, pseudoElt?: string | null): CSSStyleDeclaration;
    getComputedStyle(elt: Element, callback: (result: CSSStyleDeclaration) => void): void;
    getComputedStyle(elt: Element, pseudoElt: string | null, callback: (result: CSSStyleDeclaration) => void): void;
}

The following assertion holds true for legacy browsers:

// actual will only be undefined in modern browsers.
let actual = window.getComputedStyle(elt, function() {});
// expected will always be a CSSStyleDeclaration
let expected = window.getComputedStyle(elt);

// This works in legacy browsers:
assert.deepEqual(actual, expected);
@ExE-Boss ExE-Boss changed the title [cssom] Allow passing a callback to window.getComputedStyle [cssom] Allow passing a callback to window.getComputedStyle(…) Jan 31, 2019
@upsuper
Copy link
Member

upsuper commented Jan 31, 2019

If we want it to be asynchronous, it would probably be better to add another function which returns a Promise<CSSStyleDeclaration> or so. But before that, could you elaborate why you want an asynchronous gCS? What usecase are you trying to solve?

@emilio
Copy link
Collaborator

emilio commented Jan 31, 2019

getComputedStyle is already "asynchronous" in the sense that it does no work until you call getPropertyValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants