initialize method
initializes the model by starting brokers
Implementation
@override
Future<void> initialize() async {
// initialize should only run once
if (_initialized.isCompleted || _initializing.isCompleted) return;
// signal initializing in progress
_initializing.complete(true);
// build stash
if (domain != null) {
// initialize stash scope
var scope = Scope(id: 'STASH');
// initialize the stash
_stash = await Stash.get(domain!, scope: scope);
// set stash observables
for (var entry in _stash!.map.entries) {
_stash!.scope!.setObservable(entry.key, entry.value);
}
// add STASH scope
scopeManager.add(scope);
}
// add SYSTEM scope
scopeManager.add(System().scope!);
// add THEME scope
scopeManager.add(System.theme.scope!);
// add USER scope
scopeManager.add(_user.scope!);
// add GLOBAL alias to this scope
scopeManager.add(scope!, alias: "GLOBAL");
// load config file from remote
await _loadConfig();
// get global template
// get global.xml
if (domain != null) {
var uri = Uri.tryParse(domain!)?.setPage("global.xml");
if (uri != null) {
var template =
await TemplateManager().fetch(url: uri.url, refresh: true);
// deserialize the returned template
if (template.document != null && !template.isAutoGeneratedErrorPage) {
deserialize(template.document!.rootElement);
}
}
}
// mark initialized
_initialized.complete(true);
}