I'm using the library StratifiedJS (http://onilabs.com/stratifiedjs) to construct an api database synchronous.
But I am confused about how to include files.
As the documentation says, I import the library this way:
<script type="text/javascript" src="js/stratified.js" main="js/index.sjs"></script>
My index.sjs file have this code:
db = require("mongo");
var data = db.find({collection: "itens"});
Thi find
method in the module mongo has this code:
exports.find = function(params) {
waitfor(var rows) {
$.getJSON("db/find", params, function(result){
resume(result.rows);
});
}
return rows;
}
When I access the db module through file index.sjs or via a script inside a tag:
<script type="text/sjs"> ... code .. </ script>
the code works perfectly. But when I try to access through a file of type "text/javascript"
behavior changes.
In this case if I run the code below into a file .js
:
var data = db.find({collection: "itens"});
The data variable will not contain the returned data from base, beacause the code return rows;
runs before the getJSON
callback function to be executed;
My question is: how do I then run the modules declared in sjs files in the javascript file type.