I have a RequireJS module and I want to only return an object after it's onReady() event has been called.
define([
'kendovendor',
'TodoDB',
'jaydatakendo'
], function (kendo,tododb,jdvend) {
var onlinedb = new Avcheck.Layered.Model.AvCheckContext({
name: 'oData',
oDataServiceHost: '/WcfDataServiceTest.svc'
});
var offlinedb = new Avcheck.Layered.Model.AvCheckContext({
name: 'webSql',
databaseName: 'TodoDB'
});
var fullDB;
offlinedb.onReady(function () {
fullDB = onlinedb.AChecklistComplete.include('AChecklistTop').include('Aircraft').include('Aircraft.Vendor').asKendoDataSource();
//calling this inside onReady() returns nothing as there is a timing issue
return {
onlinedb: onlinedb,
offlinedb: offlinedb,
FullDB: fullDB
};
});
});
The reason for this is that the JayData include() will only work after the database is ready. But another module is using this module as a requirement, and this module returns nothing. If I call return outside of onReady(), then it returns a valid object, but FullDB is not set properly.
How can I set up RequireJS to work nicely with an objects onready() event? Thanks.