Skip to content

Intersection observer api #584

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

Closed
wants to merge 2 commits into from
Closed

Intersection observer api #584

wants to merge 2 commits into from

Conversation

sjorsdonkers
Copy link
Contributor

IntersectionObserver implementation using polyfill.
Additional apis needed to make this work.

This turns out to be a good test to make sure the IsolatedWorld works correctly.
A Zig native implementation is likely preferable in the future.

*/
IntersectionObserver.prototype._getRootRect = function() {
console.log('window.document: '+ window.document);
console.log('document: '+ document);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document == null 🧐

Copy link
Contributor Author

@sjorsdonkers sjorsdonkers Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click.js Executes the following in the isolated world:

const visibleRatio = await new Promise(resolve => {
    const observer = new IntersectionObserver(entries => {
        resolve(entries[0].intersectionRatio);
        observer.disconnect();
    });
    observer.observe(element);
});
return threshold === 1 ? visibleRatio === 1 : visibleRatio > threshold;

Note that opt_options is not passed so this.root is null meaning document should be used as root

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a lot of work to add natively to Zig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly wanted to learn and understand the polyfills, then solve the core issues.
With the current code it runs, but returns false instead of true for the click example.
So I think that is the right time to switch to a native Zig implementation.
I'll make a new PR to at least add loading the polyfill and make issues for the isolated page recreation and delay loading polyfills issues.

Base automatically changed from share-state-and-global-with-the-isolated to main April 30, 2025 11:55
});

pub const CSSStyleDeclaration = struct {
pub fn get_display(_: *CSSStyleDeclaration) []const u8 {
return "anythingbutnotnone";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unset is probably better (it has a real meaning here)

});

pub const CSSStyleDeclaration = struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe moved to the css folder?

Copy link
Contributor Author

@sjorsdonkers sjorsdonkers Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're too fast lol, I'm closing this PR

@sjorsdonkers sjorsdonkers deleted the intersectionobserver branch May 5, 2025 10:31
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants