-
Notifications
You must be signed in to change notification settings - Fork 16
/
angular-hot-replacement.js
72 lines (55 loc) · 2.01 KB
/
angular-hot-replacement.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
/* Angular Hor Module Replacement */
var HotAngular = function() {
this.ANGULAR_MODULE;
this.MODULE_CACHE;
this.cache = {};
this.configCache = {};
this.factoryCache = {};
this.serviceCache = {};
this.templateCache = {};
this.controllerCache = {};
this.name;
this.bootstrapElement;
this.element = document.querySelector('[ng-app]');
this.originalContent = this.element.innerHTML;
};
// Angular functions to replace
HotAngular.prototype.run = require('./interceptors/run');
HotAngular.prototype.value = require('./interceptors/value');
HotAngular.prototype.module = require('./interceptors/module');
HotAngular.prototype.config = require('./interceptors/config');
HotAngular.prototype.filter = require('./interceptors/filter');
HotAngular.prototype.factory = require('./interceptors/factory');
HotAngular.prototype.service = require('./interceptors/service');
HotAngular.prototype.constant = require('./interceptors/constant');
HotAngular.prototype.provider = require('./interceptors/provider');
HotAngular.prototype.animation = require('./interceptors/animation');
HotAngular.prototype.directive = require('./interceptors/directive');
HotAngular.prototype.controller = require('./interceptors/controller');
HotAngular.prototype.reloadState = function() {
var elm = this.bootstrapElement;
if (elm) {
if (elm.injector().has('$state')) {
console.log('Reloading State');
var $state = elm.injector().get('$state');
$state.transitionTo($state.current, $state.params, {
reload: true,
inherit: false,
notify: true
});
} else {
elm.injector().get('$compile')(elm.contents())(elm.scope());
}
}
};
HotAngular.prototype.recompile = function() {
var elm = this.bootstrapElement;
console.log('Recompile App');
//elm.injector().get('$compile')(this.originalContent)(elm.scope());
window.location.reload();
};
HotAngular.prototype.test = function(webpackModule) {
this.webpackModule = webpackModule;
return this;
}
module.exports = new HotAngular();