/
host.component.ts
46 lines (37 loc) · 1.3 KB
/
host.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Component, OnInit, Injector } from '@angular/core';
import { ReactChildComponentView } from '../react/child/child';
import { ValueStore } from './redux/list.store';
import { add, remove } from './redux/list.action';
import { Model } from '../../domain/model';
@Component({
selector: 'host-component',
templateUrl: 'app/components/host/host.component.html',
styleUrls: ['app/components/host/host.component.css'],
providers: [
Model
]
})
export class HostComponent implements OnInit {
public store: ValueStore;
public val: string = 'red';
constructor( public model: Model, public injector: Injector ) {
this.initStore();
console.log('Resolved model instance: ' + model.uuid);
}
public initStore() {
this.store = new ValueStore( this.model.colors );
this.store.store.subscribe(() => {
console.log('on state change (angular 2 host): ' + this.store.store.getState().length);
});
}
public ngOnInit() {
ReactChildComponentView.initialize( this.model.componentTitle, this.store, 'react-component-container', this.injector );
ReactChildComponentView.initialize( this.model.componentTitle, this.store, 'react-component-container-2', this.injector );
}
public onAdd() {
this.store.dispatch( add( this.val ) );
}
public onRemove() {
this.store.dispatch( remove ( this.val ) );
}
}