Git Product home page Git Product logo

yabble's Introduction

A general purpose browser-side CommonJS module loader 

Yabble is a general purpose browser-side CommonJS module loader. Other similar module loaders are available, but Yabble strives to be a flexible loader in a small package.

To see live unit tests, visit:
http://jbrantly.github.com/yabble/test/index.html

To see an overview of the goals, visit:
http://blog.jbrantly.com/2010/04/introducing-yabble.html

Features:
 * Compliant with Modules 1.1.1
 * Supports async XHR/eval()
   - Allows the use of non-transport-wrapped module code for quick development
 * Supports script tags with a Transport format
   - Easier debugging, potential for file concatenation
   - Supports Transport/D and Transport/C
 * Supports require.ensure() for lazy-loading modules
 * Passes unit tests on YUI's A-grade browsers
 * Includes a tool for automatically wrapping modules in a Transport format
 * Small size (<600 lines, ~15kb raw, ~5kb minified, and ~2kb when minified/gzipped)

Roadmap:
 * Stability
   - Even more cross-browser testing
   - More unit tests for Async/A
 * Features
   - Async/A error handling once its decided (maybe before)
   - Tested support for loading from another domain (it may work now..)
 * Documentation
 * Tooling
   - Currently under-developed. Not recommended to use.
   - Use loader code in tooling (no copy/paste code)
   - Explicit support for concatenated Transport files tooling (loader should already support)   
   - Expand supported engines for tooling (node.js)
   - Better consideration for platform (line endings, encoding, etc)

Usage:

require.setModuleRoot(path)

   Use this to configure the root path to find modules. Think of this as a 
   single entry in require.paths.

require.useScriptTags()

   The default behavior is to use XHR+eval() and expects unwrapped modules. Call this method
   to configure Yabble to use script tags and expect wrapped modules.
    
require.run(programId)

   This kicks off an application using the specified module ID.
   
require.ensure(dependencies, callback)

   See Async/A for more details. Can be used to retrieve modules and run code without using
   require.run().

See unit tests for example usage.

Changelog:

v0.3.0 (2010-04-18)
	- Restructured to use Packages/1.0

v0.2.0 (2010-04-14)
	- Now using QUnit for unit tests
	- Added support for Modules 1.1.1 plus unit tests
	- Finished support for Transport/D plus unit tests
	- Added support for Transport/C plus unit tests
	- Added unit tests for Async/A and fixed bugs
	- Added unit tests for resolveModuleId and determineShallowDependencies

v0.1.0 (2010-04-12)
	- Initial commit

yabble's People

Contributors

jbrantly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yabble's Issues

Does not register module.

Example:

require.def({
    "underscorex": {
        injects: [ 'require', 'exports', 'module' ],
        factory: function (require, exports, module) {

            var _ = exports = module.exports = require('underscore');
            console.log(_)

            // libary defined here
        }
    },
    "underscore": {
        injects: [ 'require', 'exports', 'module' ],
        factory: function (require, exports, module) {


            var _ = ...

            // Must be commented out, because Yabble does not define module.exports
            if (typeof module !== 'undefined'/* && module.exports*/) {
            module.exports = _;
                _._ = _;
            } else {
                root._ = _;
            }

            // libary defined here
        }
    }
})

console.log() prints {} instead of the underscore library.

Transport/D + injects: module.exports === undefined

Some libraries (example: underscore) are using checks whether module.exports is defined, but when I define a module with Transport/D and injects. module and exports are defined but module.exports (=== exports) is not.

require.def({ name: { injects: [ 'require', 'exports', 'module' ], factory: function (require,exports,module) { ... } } })

Some tests are failing

I use 64-bit Arch Linux and Chromium 5.0.342.9 (43360).

Modules/1.0 – all failed
Modules/1.1.1 – all failed
Modules/1.1.1 Wrapped – 9 passed, 3 failed
Async/A – all failed
determineShallowDependencies() – all failed

The error that I see most often is “Died on test #1: NETWORK_ERR: XMLHttpRequest Exception 101.”, but there’s also stuff like “FAIL module.uri is absolute and ends with program.js”.

Does not resolve paths?

In test.html

<script type="text/javascript" src="yabble/lib/yabble.js"></script>
<script type="text/javascript">

    require.useScriptTags()
    require.ensure(['module'], function (require) {

        console.log(require('module')) // *)
    })

</script>

module.js is in the same path:

require.def({
    m: function (require, exports, module) {

        exports.name = 'm'
        exports.other = require('ok/other')
    },
    module: function (require, exports, module) {

        exports.name = 'module'
        exports.m = require('m')
        exports.other = require('ok/other')
    }
}, ['ok/other'])

ok/other.js:

require.def({other:function(require, exports, module) {

    exports.name = 'other'
}})

Both files finish loading with script tags, but I get this error in this line (*):

Uncaught Error loading module

It seems that yabble hasn't registered the module although the scripts have successfully loaded. Same result, if I explicitly set the module root.

  • Using the path ./ok/other will result in this error:

    Uncaught TypeError: Object [object DOMWindow] has no method '_resolveModuleId'

  • Passing the absolute URI is failing as well.

  • Putting other.js in root is working.

Impossible to give param to require.run

Using params on to the main() call can be very usefull (flexibility, reusability, ...) : require.run("app/main", [params], cb).
For instance by calling several instance of an application using different parameters ...

example:

//index.html
[...]
url = http://localhost/app/foo/bar;
require.setModuleRoot(url);
require.run("app", [url]);
[...]

//app.js
[...]
function main(url) {
//some work using url
}
[...]

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.