Skip to content

Instantly share code, notes, and snippets.

@bgerrissen
Created November 24, 2010 13:09
Show Gist options
  • Save bgerrissen/713629 to your computer and use it in GitHub Desktop.
Save bgerrissen/713629 to your computer and use it in GitHub Desktop.
Record mechanism Require JS (modulejs variant)

Record mechanism Require JS (modulejs variant)

Record object

{
    path : "foo/bar",         // final path/id
    needs : [],               // should stay intact
    fetch : [],               // each dependency is destroyed once it's completed
    status : 0,               // module status; new, loading, pending, complete, failed
    context : "http://etc",   // root dir containing path
    extention : ".js",        // will be pasted behind path
    node : nodeObj,           // first node constructor and later constructed node
    factory : function(){},   // module factory
    module : undefined,       // either: a.) result of factory, b.) object or c.) undefined
    timeoutID : 1             // used for script timeouts
}

Status mapping of record

-1 // FAILED
0 // NEW
1 // LOADING
2 // PENDING (rename to LOADED ?)
3 // COMPLETE

Description of what happens at each stage, using status in order:

@status new

Whenever a dependency path is declared and not present in the registry, the following happens.

  1. a record is created and stored in registry
  2. status is set to 0 (new)
  3. context for path is retreived from context mappings (url prefix)
  4. extention is set to ".js"
  5. node constructor is set to default ScriptNodeConstructor
  6. Path expression (if any) methods are executed for record (See path expressions gist).

@loading

Fires per dependency when it's loading html node is constructed and appended to a DOM fragment (before it actually starts the load). At this stage it's futile to tweak relevant attributes required before a load.

  1. Status is set to 1 (loading)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment