Giter VIP home page Giter VIP logo

Comments (3)

errorrik avatar errorrik commented on August 16, 2024

活的循环依赖需要区分装载时依赖和运行时依赖,但是这事只能通过ast分析做到。在loader里,对体积要求比较高,无法这么做。如果想要保证所有活依赖的场景都能被执行(上面的场景用requirejs去require['x2']就无法运行下去),就需要一个try factory invoke机制。所以,factory被重复invoke,是可能的

不过, @100pah 给出的场景里,确实可以看出,esl1.6的module init过程做了多余的invoke,module init完成后factory就不该再被invoke了。这应该是event emit时机导致的。这个问题经过测试在正在开发的1.8中已经有了改进。

from esl.

100pah avatar 100pah commented on August 16, 2024

恩,

factory被invoke多次可能导致的业务逻辑问题比如:
单例变成了多例;一个“OO类”被创建两次导致继承关系判断失效等;
而且factory被调用几次何时调用,开发时并不可自知。

假如能保证 只存在“运行时循环依赖”时,factory至多只会被invoke一次 就已经能解决很大问题了。
如果没有这种保证,则可能不敢使用“循环依赖”这个特性。

from esl.

otakustay avatar otakustay commented on August 16, 2024

其实这个问题基本能通过把require尽量放在最前面来解决……

from esl.

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.