/
setup-registry.ts
107 lines (89 loc) · 3.79 KB
/
setup-registry.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { hasDOM } from '@ember/-internals/browser-environment';
import { privatize as P, Registry } from '@ember/-internals/container';
import { ENV } from '@ember/-internals/environment';
import { Simple } from '@glimmer/interfaces';
import Component from './component';
import Checkbox from './components/checkbox';
import LinkToComponent from './components/link-to';
import TextArea from './components/text_area';
import TextField from './components/text_field';
import {
clientBuilder,
DOMChanges,
DOMTreeConstruction,
NodeDOMTreeConstruction,
rehydrationBuilder,
serializeBuilder,
} from './dom';
import Environment from './environment';
import loc from './helpers/loc';
import { InertRenderer, InteractiveRenderer } from './renderer';
import TemplateCompiler from './template-compiler';
import ComponentTemplate from './templates/component';
import OutletTemplate from './templates/outlet';
import RootTemplate from './templates/root';
import OutletView from './views/outlet';
export function setupApplicationRegistry(registry: Registry) {
registry.injection(
'service:-glimmer-environment',
'appendOperations',
'service:-dom-tree-construction'
);
registry.injection('renderer', 'env', 'service:-glimmer-environment');
// because we are using injections we can't use instantiate false
// we need to use bind() to copy the function so factory for
// association won't leak
registry.register('service:-dom-builder', {
create({ bootOptions }: { bootOptions: { _renderMode: string } }) {
let { _renderMode } = bootOptions;
switch (_renderMode) {
case 'serialize':
return serializeBuilder.bind(null);
case 'rehydrate':
return rehydrationBuilder.bind(null);
default:
return clientBuilder.bind(null);
}
},
});
registry.injection('service:-dom-builder', 'bootOptions', '-environment:main');
registry.injection('renderer', 'builder', 'service:-dom-builder');
registry.register(P`template:-root`, RootTemplate);
registry.injection('renderer', 'rootTemplate', P`template:-root`);
registry.register('renderer:-dom', InteractiveRenderer);
registry.register('renderer:-inert', InertRenderer);
if (hasDOM) {
registry.injection('service:-glimmer-environment', 'updateOperations', 'service:-dom-changes');
}
registry.register('service:-dom-changes', {
create({ document }: { document: Simple.Document }) {
return new DOMChanges(document);
},
});
registry.register('service:-dom-tree-construction', {
create({ document }: { document: Simple.Document }) {
let Implementation = hasDOM ? DOMTreeConstruction : NodeDOMTreeConstruction;
return new Implementation(document);
},
});
}
export function setupEngineRegistry(registry: Registry) {
registry.register('view:-outlet', OutletView);
registry.register('template:-outlet', OutletTemplate);
registry.injection('view:-outlet', 'template', 'template:-outlet');
registry.injection('service:-dom-changes', 'document', 'service:-document');
registry.injection('service:-dom-tree-construction', 'document', 'service:-document');
registry.register(P`template:components/-default`, ComponentTemplate);
registry.register('service:-glimmer-environment', Environment);
registry.register(P`template-compiler:main`, TemplateCompiler);
registry.injection('template', 'compiler', P`template-compiler:main`);
registry.optionsForType('helper', { instantiate: false });
registry.register('helper:loc', loc);
registry.register('component:-text-field', TextField);
registry.register('component:-text-area', TextArea);
registry.register('component:-checkbox', Checkbox);
registry.register('component:link-to', LinkToComponent);
if (!ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS) {
registry.register(P`component:-default`, Component);
}
}