can't access promiseModule.currentContext

5 views
Skip to first unread message

W.S. Hager

unread,
Feb 19, 2013, 6:42:37 AM2/19/13
to persevere...@googlegroups.com
Hi,

I've been moving domain-specific modules+facets to a separate folder within persevere-example-wiki, and mixing them in with the rest upon request using the host. My app.js has another setup, mainly using this code to do the redirect:

pinturaConfig.getDataModel = function(request){
var domain = request.host;
if(path.existsSync("./domains/"+domain+"/datamodel.js")) {
            // mixin models into fullModel, userModel & publicModel
}
// return datamodel based on user
}

This works well, except in one respect: I can't access the promiseModule.currentContext in the models/facets in the domain folder.

My question is: how does promiseModule.currentContext even work? It's not accessed globally, but always via require, and I can't see how the currentContext gets set in the normal case, let alone why it isn't in mine.

Any help would be appreciated a lot!

Thanks.

Wouter

-- 

W.S. Hager
Lagua Web Solutions
http://lagua.nl

W.S. Hager

unread,
Feb 19, 2013, 6:53:37 AM2/19/13
to persevere...@googlegroups.com
Ah I see requirejs is using a context. How to set the proper context for my case?

Thanks.


2013/2/19 W.S. Hager <wsh...@gmail.com>

W.S. Hager

unread,
Feb 19, 2013, 8:01:04 AM2/19/13
to persevere...@googlegroups.com
Ok I figured this out. The problem was indeed that the context of the require was in the getDataModel function. When I required the domain datamodel in the context of app.js it worked.


2013/2/19 W.S. Hager <wsh...@gmail.com>

W.S. Hager

unread,
Feb 20, 2013, 3:40:53 AM2/20/13
to persevere...@googlegroups.com
Hi,

As discussed, I setup persvr to change the model directory on request. Can anyone tell me if this code will have a performance impact or other nasty side-effects? So far I noticed none, but the code won't win the beauty contest. I had to add these lines to app.js (don't try this at home):

var fM,pM,uM;
var domains = {
mydomain:require("./domains/mydomain/datamodel")
};
pinturaConfig.getDataModel = function(request){
var user = request.remoteUser;
var domain = request.host;
if(domains[domain]) {
fM = mixin(fullModel,domains[domain].fullModel);
pM = mixin(publicModel,domains[domain].publicModel);
uM = mixin(userModel,domains[domain].userModel);
} else {
fM = fullModel;
pM = publicModel;
uM = userModel;
}
// reload schemas into modelStore
// initializeRoot won't work because the schemata in the model store cannot be overwritten
// so recreate it and call initializeRoot addClass=false to reset the model paths
// FIXME: only recreate if domain changes
var schemas = {};
for(var i in fM){
schemas[i] = fM[i].instanceSchema;
}
var modelStore = Memory({index: schemas});
require("perstore/model").initializeRoot(fM);
fM.Class = Model(modelStore, modelSchema); uM.Class = pM.Class = Restrictive(fM.Class); if(user){ if(admins.indexOf(user)>-1){ return fM; // admin users can directly access the data model without facets } return uM; } return pM;
}

Any advice much appreciated.

Thanks.

Wouter


2013/2/19 W.S. Hager <wsh...@gmail.com>
Reply all
Reply to author
Forward
0 new messages