Git Product home page Git Product logo

Comments (2)

dmvaldman avatar dmvaldman commented on May 18, 2024

200 is definitely an arbitrary number. It's not clear that just waiting one frame will be enough either though, because the rate at which resize events are emitted is not tied to the request animation frame loop. I'll take a closer look though to test your suggestion. If resize events are called faster than the request animation frame, we're good (this may be hardware dependent, not sure if there's a spec). If not then a fudge factor (like 200ms) might be needed, though 200 is generous. Really there's no significant problem with having the end event fired 200ms after the last resize event. In the future, I'd like to manually limit the DOM events to fire at most once per request animation frame loop (taking the last event fired in the loop and ignoring the others).

For clarity on the code, the point of the debounce is to convert a continuously emitted resize event into start, update and end events to fit the architecture. The first resize event can easily be detected and converted to a start. The last one can only be detected with a debounce style call.

from samsara.

dmvaldman avatar dmvaldman commented on May 18, 2024

After some testing, I've found the resize event to be triggered slower than the request animation frame loop. Browsers likely throttle the event internally. This forces us to keep a fudge factor, but I've decided to lower it slightly to 150ms.

Whatever value is chosen will cause a lag if there is a sudden resize event triggered. For instance, opening and closing the dev tools on a desktop browser, or changing the orientation from landscape to portrait (or vice versa) on a mobile app. The view won't update responsively for the duration of 150ms.

This is undesirable, however, at least on mobile you can detect for this (because the only resize events from orientation change are discrete in nature). So we can remove any lag on mobile orientation resizes.

This has been updated in 4f681de

from samsara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.