Giter VIP home page Giter VIP logo

Comments (8)

getify avatar getify commented on July 27, 2024

Despite the fact that it may have worked in the past, it's not really a supported use case that you "suspend" the execution of a chain and then resume it later after some other logic. There's lots of potential race conditions such activity could introduce. Your usage is not really an intended or supported functionality, at least for now. Perhaps the re-write I'm working on will be more robust for it, but honestly that won't be a major design goal.

May I ask, why do you need to resume the $LAB chain later? Why not use another chain, or just execute the code right away?

from labjs.

lunetics avatar lunetics commented on July 27, 2024

Currently i load mootools core and LABjs via standard script tag, then the additional JS like mootools-more, clientcide and my own modules, so the domready occurs before my own modules are loaded via script tag.

So with the instance - chain i can make sure that my modules are loaded before i try to use it in inline code, otherwise it can happen that js don't know the module / class cause its not loaded yet.

At least i would wish there was a .completed() function which (similar to wait, but fires parallel)

from labjs.

getify avatar getify commented on July 27, 2024

But I'm still not sure I understand why this implies that you need to split up the $LAB chain? I understand using a script tag to blocking load of mootools (because of doc.write) and LABjs, but then just need one chain that loads all the other JS files, right? Also, how does loading in CSS in the middle of all that factor in?

from labjs.

lunetics avatar lunetics commented on July 27, 2024

The CSS breaks the chain somehow, don't know why.
I built a lablsloaded Eventhandler for mootools, so when the scriptchain is loaded. i set at the footer async.wait(function() {Browser.labjsloaded = true} and check via the handler. Maybe i set different breakpoints for different modules, don't know if that complexity is worth the few microseconds gain then.

from labjs.

aakoch avatar aakoch commented on July 27, 2024

I don't understand why you can't do this:
var asyncjs = $LAB
.script('mootools-more').wait()
.script('clientcode').wait()
.script('my own modules').wait(function() {
alert('Scripts Loaded');
alert('first call');
alert('second call');
alert('third call');
});
then some CSS via link tag.

You mentioned something about inline Javascript. If you're trying to prevent that code from being run until all of the scripts are loaded, why not just use the <script> tag to load all of the scripts? This would prevent the domready event from being fired until your own modules are loaded.

from labjs.

lunetics avatar lunetics commented on July 27, 2024

well i have another approch now with mootools.

 
$Lab
.script(mootools...).wait()
.script(...).wait(function() {
Browser.labjsloaded = true;
}

and a custom eventhandler:


Element.Events.labjsloaded = {
    onAdd: function(fn){        
        if (Browser.labjsloaded) fn.call(this);
    }
};
(function(){
    var labjsloaded = function(){
        console.log('Labs Ready')
        window.fireEvent('labjsloaded');
        document.fireEvent('labjsloaded');
    };            
    var repeat = function(){
        (Browser.labjsloaded == true) ? labjsloaded() : repeat.delay(10);
    }
    repeat();
})();

so i can use now:


window.addEvent('labjsloaded',function() {
// do this after the scripts are loaded...
});

from labjs.

getify avatar getify commented on July 27, 2024

closing.

from labjs.

getify avatar getify commented on July 27, 2024

FYI: resuming of $LAB chains will be supported in 2.0.

from labjs.

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.