Skip to content

Instantly share code, notes, and snippets.

@JeroenVinke
Last active February 26, 2016 18:10
Show Gist options
  • Save JeroenVinke/ee72e9331e645f84c26a to your computer and use it in GitHub Desktop.
Save JeroenVinke/ee72e9331e645f84c26a to your computer and use it in GitHub Desktop.
import {inject, noView, ViewCompiler, ViewResources, Container, ViewSlot} from 'aurelia-framework';
@noView
@inject(ViewCompiler, ViewResources, Container)
export class ViewFactory {
constructor(viewCompiler, resources, container) {
this.viewCompiler = viewCompiler;
this.resources = resources;
this.container = container;
}
insert(containerElement, html, viewModel) {
let viewFactory = this.viewCompiler.compile(html, this.resources);
let view = viewFactory.create(this.container);
view.bind(viewModel, this);
let anchorIsContainer = true,
viewSlot = new ViewSlot(containerElement, anchorIsContainer);
viewSlot.add(view);
viewSlot.attached();
return () => viewSlot.remove(view);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment