forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathview.ts
More file actions
62 lines (53 loc) · 2.12 KB
/
view.ts
File metadata and controls
62 lines (53 loc) · 2.12 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {BaseException} from 'angular2/src/core/facade/exceptions';
import {ListWrapper, MapWrapper, Map, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {isPresent, isBlank, stringify} from 'angular2/src/core/facade/lang';
import {
RenderViewRef,
RenderEventDispatcher,
RenderTemplateCmd,
RenderProtoViewRef,
RenderFragmentRef
} from './api';
export class DefaultProtoViewRef extends RenderProtoViewRef {
constructor(public cmds: RenderTemplateCmd[]) { super(); }
}
export class DefaultRenderFragmentRef<N> extends RenderFragmentRef {
constructor(public nodes: N[]) { super(); }
}
export class DefaultRenderView<N> extends RenderViewRef {
hydrated: boolean = false;
eventDispatcher: RenderEventDispatcher = null;
globalEventRemovers: Function[] = null;
constructor(public fragments: DefaultRenderFragmentRef<N>[], public boundTextNodes: N[],
public boundElements: N[], public nativeShadowRoots: N[],
public globalEventAdders: Function[]) {
super();
}
hydrate() {
if (this.hydrated) throw new BaseException('The view is already hydrated.');
this.hydrated = true;
this.globalEventRemovers = ListWrapper.createFixedSize(this.globalEventAdders.length);
for (var i = 0; i < this.globalEventAdders.length; i++) {
this.globalEventRemovers[i] = this.globalEventAdders[i]();
}
}
dehydrate() {
if (!this.hydrated) throw new BaseException('The view is already dehydrated.');
for (var i = 0; i < this.globalEventRemovers.length; i++) {
this.globalEventRemovers[i]();
}
this.globalEventRemovers = null;
this.hydrated = false;
}
setEventDispatcher(dispatcher: RenderEventDispatcher) { this.eventDispatcher = dispatcher; }
dispatchRenderEvent(boundElementIndex: number, eventName: string, event: any): boolean {
var allowDefaultBehavior = true;
if (isPresent(this.eventDispatcher)) {
var locals = new Map<string, any>();
locals.set('$event', event);
allowDefaultBehavior =
this.eventDispatcher.dispatchRenderEvent(boundElementIndex, eventName, locals);
}
return allowDefaultBehavior;
}
}