Code Monkey home page Code Monkey logo

Comments (3)

alanwei0 avatar alanwei0 commented on May 25, 2024

@hustcc
如果要复用ResizeObserver的话,那么任意一个被observe的元素改变size的时候都会触发下面的回调函数,然而在entries里包含所有被observe的元素,所以要找到实际变更的那个元素的话,就需要手动比较元素size是否变化,还需要增加一个数据结构维护元素上次变更后的大小。个人感觉这种改动之后收益并不明显,而且可能增加bug风险。

const sizeChanged = currentSize => {
    // compare currentSize with oldSize
};

const resizeObserver = new ResizeObserver(entries => {
    // loop in all observed elements
    for (let entry of entries) {
        // we have to diff the size change by ourselves
        if (sizeChanged(entry.contentRect)) {
            // invoke corresponding callbacks
        }
    }
});

What's your opinion?

from size-sensor.

hustcc avatar hustcc commented on May 25, 2024

sizeChanged 函数不需要吧,只要触发了就 触发 listener 就好了。只需要维护一个 element 和 listener 之间对应关系的。

from size-sensor.

alanwei0 avatar alanwei0 commented on May 25, 2024

必须要sizeChanged吧,不然怎么判断到底是哪一个element变化了

from size-sensor.

Related Issues (10)

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.