Created
August 24, 2012 20:33
-
-
Save samdelagarza/3455313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├───src | |
│ ├───client | |
│ │ ├───apps | |
│ │ │ ├───balance | |
│ │ │ │ └───tests | |
│ │ │ │ └───mocha | |
└────BalanceViewModel_spec.js | |
│ │ │ │ └───BalanceViewModel.js | |
└───tools | |
├───requirejs | |
└───r.js | |
****************** contents of BalanceViewModel_spec.js ********************** | |
var path = module.require('path'), | |
rootPath = path.join(__dirname, "../../"), | |
requirejs = module.require(path.resolve('../tools/requirejs/r.js')); | |
requirejs.config({ | |
baseUrl:rootPath, | |
nodeRequire:require, | |
paths:{ | |
'BalanceViewModel':'./BalanceViewModel' | |
} | |
}); | |
var ViewModel = requirejs('BalanceViewModel'); | |
console.log('BalanceViewModel: ', ViewModel); | |
****************** contents of BalanceViewModel.js ********************** | |
define(function () { | |
console.log('inside of balance view model'); | |
return function () { | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@samdelagarza: OK, so the issue is the synchronous requirejs('') call. It looks like there was a change in behavior from 1.0, and I filed this bug to track the fix, marked for 2.1. However if I do another 2.0.x point release it will be included in that release:
requirejs/r.js#271
You can try out the fix using the latest master snapshot:
https://raw.github.com/jrburke/r.js/master/dist/r.js
That said, support for this top level synchronous requirejs('') use may change in the future. As part of normalizing expectations across environments, I may convert r.js to be fully async, in which case this will fail at that time. The better solution is to use the callback version of requirejs at this top level, and this works today with 2.0.6:
While it ends up today that the callback function is called synchronously, that may change in the future.
If you have feedback on this, it is best to comment in that r.js issue mentioned above, as I do not seem to be getting notifications from github on this gist.