GithubHelp home page GithubHelp logo

isabella232 / step Goto Github PK

View Code? Open in Web Editor NEW

This project forked from requirejs/step

0.0 0.0 0.0 56 KB

AMD loader plugin that takes a step config to know how to sequential load some files

License: Other

Shell 0.04% JavaScript 94.68% HTML 5.29%

step's Introduction

step

An AMD loader plugin for loaders like RequireJS that will load scripts in steps.

This allows you to load traditional scripts that do not use AMD in a sequential fashion.

You should prefer the built-in shim config in RequireJS to step, since it is more expressive and allows you to get local exports references.

If you have a bunch of scripts with dependency sets that would make shim hard to use, then this plugin may help.

Usage

step only works with AMD loaders that support module config, like RequireJS 2.0.

First, set up a module config for step and list out the steps in a steps property:

require.config({
    config: {
        step: {
            steps: [
                ['one'],
                ['two'],
                ['three'],
                ['four']
            ]
        }
    }
});

In this example, four depends on three, two and one being loaded in order.

Then, to load a dependency along with anything in previous steps, use the step! loader prefix ID:

define(['step!four'], function () {
    //one.js, two.js and three.js will have also been
    //loaded by the time this function is called.

    //four.js creates a global `four` variable,
    //and it does not call define() so there
    //will not be a local `four` reference
    //passed to this function. Use the global
    //`four` instead.
    console.log(four.doSomething());
});

If you know that a script depends on two different scripts that each do not depend on each other, then you can put them in the same step. For instance, if "three" depended on "one" and "two" and "one" and "two" did not depend on each other:

require.config({
    config: {
        step: {
            steps: [
                ['one', 'two'],
                ['three'],
                ['four']
            ]
        }
    }
});

All the scripts in a step are loaded async and can load out of order, so it is important that they do not depend on each other.

Limitations

  • Only use step with scripts that do not already call define(). Similarly, do not include scripts in step that depend on AMD modules.
  • It is slower loading than loading plain AMD modules. step waits for each previous step to complete loading before doing the next step. Doing an r.js optimization build when you are ready to deploy your code is strongly suggested.
  • When doing a build, include all the steps in the build output. If you use an exclude directive to exclude a step script, it will likely break when that built file is run in the browser.
  • step will read the step config the first time it is called, and "burn in" that config internally. So, it will not understand any further step config if it is set after the first step! reference.

License

MIT

Code of Conduct

jQuery Foundation Code of Conduct.

step's People

Contributors

jrburke avatar

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.