1 | import {inject} from 'aurelia-dependency-injection';
|
2 | import {BoundViewFactory, ViewSlot, customAttribute, templateController, ViewFactory, View} from 'aurelia-templating';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | @customAttribute('replaceable')
|
8 | @templateController
|
9 | @inject(BoundViewFactory, ViewSlot)
|
10 | export class Replaceable {
|
11 |
|
12 |
|
13 | viewFactory: ViewFactory;
|
14 |
|
15 | viewSlot: ViewSlot;
|
16 |
|
17 | view: View;
|
18 |
|
19 | |
20 |
|
21 |
|
22 |
|
23 | constructor(viewFactory: ViewFactory, viewSlot: ViewSlot) {
|
24 | this.viewFactory = viewFactory;
|
25 | this.viewSlot = viewSlot;
|
26 | this.view = null;
|
27 | }
|
28 |
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 | bind(bindingContext, overrideContext) {
|
35 | if (this.view === null) {
|
36 | this.view = (this.viewFactory as any).create();
|
37 | this.viewSlot.add(this.view);
|
38 | }
|
39 |
|
40 | this.view.bind(bindingContext, overrideContext);
|
41 | }
|
42 |
|
43 | |
44 |
|
45 |
|
46 | unbind() {
|
47 | this.view.unbind();
|
48 | }
|
49 | }
|