-
-
Save samdelagarza/3455313 to your computer and use it in GitHub Desktop.
├───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 () { | |
}; | |
}); |
Sorry, I should have indicated that it's in the spec, I've annotated this in the gist above.
thanks again for your help.
@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:
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:
requirejs(['BalanceViewModel'], function (BalanceViewModel) {
});
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.
Where is the code from line 14-29 being served from? Judging from the path used to loader requirejs, it looks like it is happening from client directory. If that is the case, then the baseUrl is being set to two directories above the client directory, and that paths setting means that BalanceViewModel will be expected in that baseUrl, which is not where that file will be.
But maybe I am misunderstanding where those lines are being run.