-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathcurly-component-state-bucket.ts
75 lines (63 loc) · 1.84 KB
/
curly-component-state-bucket.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { clearElementView, clearViewElement, getViewElement } from '@ember/-internals/views';
import { Revision, VersionedReference } from '@glimmer/reference';
import { CapturedNamedArguments } from '@glimmer/runtime';
import { Opaque, Option } from '@glimmer/util';
import Environment from '../environment';
export interface Component {
_debugContainerKey: string;
_transitionTo(name: string): void;
layoutName?: string;
attributeBindings: Array<string>;
classNames: Array<string>;
classNameBindings: Array<string>;
elementId: string;
tagName: string;
isDestroying: boolean;
appendChild(view: {}): void;
trigger(event: string): void;
destroy(): void;
setProperties(props: { [key: string]: any }): void;
}
type Finalizer = () => void;
// tslint:disable-next-line:no-empty
function NOOP() {}
/**
@module ember
*/
/**
Represents the internal state of the component.
@class ComponentStateBucket
@private
*/
export default class ComponentStateBucket {
public classRef: Option<VersionedReference<Opaque>> = null;
public argsRevision: Revision;
constructor(
public environment: Environment,
public component: Component,
public args: CapturedNamedArguments | null,
public finalizer: Finalizer,
public hasWrappedElement: boolean
) {
this.classRef = null;
this.argsRevision = args === null ? 0 : args.tag.value();
}
destroy() {
let { component, environment } = this;
if (environment.isInteractive) {
component.trigger('willDestroyElement');
component.trigger('willClearRender');
let element = getViewElement(component);
if (element) {
clearElementView(element);
clearViewElement(component);
}
}
environment.destroyedComponents.push(component);
}
finalize() {
let { finalizer } = this;
finalizer();
this.finalizer = NOOP;
}
}