Skip to content

Commit

Permalink
feat(aurelia): set root sets element in container and uses compositio…
Browse files Browse the repository at this point in the history
…n engine
  • Loading branch information
EisenbergEffect committed Jan 7, 2015
1 parent 1fac9d0 commit 9f6fa60
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/aurelia.js
@@ -1,7 +1,13 @@
import * as LogManager from 'aurelia-logging';
import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {BindingLanguage, ResourceCoordinator, ViewSlot, ResourceRegistry} from 'aurelia-templating';
import {
BindingLanguage,
ResourceCoordinator,
ViewSlot,
ResourceRegistry,
CompositionEngine
} from 'aurelia-templating';
import {Plugins} from './plugins';

var logger = LogManager.getLogger('aurelia');
Expand Down Expand Up @@ -62,21 +68,26 @@ export class Aurelia {
}

setRoot(root, applicationHost){
var compositionEngine, instruction = {};

if (!applicationHost || typeof applicationHost == 'string') {
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
} else {
this.host = applicationHost;
}

this.host.aurelia = this;
this.container.registerInstance(Element, this.host);

compositionEngine = this.container.get(CompositionEngine);
instruction.viewModel = root;
instruction.viewSlot = new ViewSlot(this.host, true);
instruction.container = this.container;

return this.container.get(ResourceCoordinator)
.loadElement(root).then(type => {
this.root = type.create(this.container);
var slot = new ViewSlot(this.host, true);
slot.swap(this.root.view);
slot.attached();
return this;
});
return compositionEngine.compose(instruction).then(root => {
this.root = root;
instruction.viewSlot.attached();
return this;
});
}
}

0 comments on commit 9f6fa60

Please sign in to comment.