Add a form of static:require_module that assumes that the factory is self-initializing
This commit is contained in:
27
common/static/common/js/utils/page_factory.js
Normal file
27
common/static/common/js/utils/page_factory.js
Normal file
@@ -0,0 +1,27 @@
|
||||
define([], function() {
|
||||
'use strict';
|
||||
|
||||
return function invokePageFactory(name, factory) {
|
||||
var args;
|
||||
|
||||
if (typeof window.pageFactoryArguments === 'undefined') {
|
||||
throw Error(
|
||||
'window.pageFactoryArguments must be initialized before calling invokePageFactory(' +
|
||||
name +
|
||||
'). Use the <%static:require_page> template tag.'
|
||||
);
|
||||
}
|
||||
args = window.pageFactoryArguments[name];
|
||||
|
||||
if (typeof args === 'undefined') {
|
||||
throw Error(
|
||||
'window.pageFactoryArguments["' +
|
||||
name +
|
||||
'"] must be initialized before calling invokePageFactory(' +
|
||||
name +
|
||||
'). Use the <%static:require_page> template tag.'
|
||||
);
|
||||
}
|
||||
factory.apply(null, window.pageFactoryArguments[name]);
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user