-
-
Notifications
You must be signed in to change notification settings - Fork 259
/
build-registry.js
88 lines (77 loc) · 2.51 KB
/
build-registry.js
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
function exposeRegistryMethodsWithoutDeprecations(container) {
var methods = [
'register',
'unregister',
'resolve',
'normalize',
'typeInjection',
'injection',
'factoryInjection',
'factoryTypeInjection',
'has',
'options',
'optionsForType'
];
function exposeRegistryMethod(container, method) {
container[method] = function() {
return container._registry[method].apply(container._registry, arguments);
};
}
for (var i = 0, l = methods.length; i < l; i++) {
exposeRegistryMethod(container, methods[i]);
}
}
export default function(resolver) {
var registry, container;
var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
});
function register(name, factory) {
var thingToRegisterWith = registry || container;
if (!container.lookupFactory(name)) {
thingToRegisterWith.register(name, factory);
}
}
if (Ember.Application.buildRegistry) {
registry = Ember.Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember.ComponentLookup);
registry = registry;
container = registry.container();
exposeRegistryMethodsWithoutDeprecations(container);
} else {
container = Ember.Application.buildContainer(namespace);
container.register('component-lookup:main', Ember.ComponentLookup);
}
// Ember 1.10.0 did not properly add `view:toplevel` or `view:default`
// to the registry in Ember.Application.buildRegistry :(
//
// Ember 2.0.0 removed Ember.View as public API, so only do this when
// Ember.View is present
if (Ember.View) {
register('view:toplevel', Ember.View.extend());
}
// Ember 2.0.0 removed Ember._MetamorphView from the Ember global, so only
// do this when present
if (Ember._MetamorphView) {
register('view:default', Ember._MetamorphView);
}
var globalContext = typeof global === 'object' && global || self;
if (globalContext.DS) {
var DS = globalContext.DS;
if (DS._setupContainer) {
DS._setupContainer(registry || container);
} else {
register('transform:boolean', DS.BooleanTransform);
register('transform:date', DS.DateTransform);
register('transform:number', DS.NumberTransform);
register('transform:string', DS.StringTransform);
register('serializer:-default', DS.JSONSerializer);
register('serializer:-rest', DS.RESTSerializer);
register('adapter:-rest', DS.RESTAdapter);
}
}
return {
registry: registry,
container: container
};
}