-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathangular.js
50 lines (39 loc) · 1.53 KB
/
angular.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
var assert = require('assert')
module.exports = toAngular
function toAngular (Nanocomponent, selector, attrs, angular) {
if (!attrs) { attrs = [] }
assert.equal(typeof Nanocomponent, 'function', 'nanocomponent-adapters/angular: component should be type function')
assert.equal(typeof selector, 'string', 'nanocomponent-adapters/angular: selector should be type string')
assert.equal(typeof attrs, 'object', 'nanocomponent-adapters/angular: attrs should be type array')
assert.equal(typeof angular, 'object', 'nanocomponent-adapters/angular: angular should be type object')
var NewComponent = function (cd, node) {
this.cd = cd
this.node = node.nativeElement
this.comp = new Nanocomponent()
this.props = {}
}
var DecorateWith = angular.Component({
selector: selector,
template: '',
changeDetection: angular.ChangeDetectionStrategy.OnPush,
inputs: attrs
})
NewComponent = DecorateWith(NewComponent)
NewComponent.parameters = [angular.ChangeDetectorRef, angular.ElementRef]
NewComponent.prototype = {}
NewComponent.prototype.constructor = NewComponent
NewComponent.prototype.ngOnChanges = function (changes) {
var _this = this
Object.keys(changes).forEach(function (change) {
_this.props[change] = changes[change].currentValue
})
if (this.comp.element) this.comp.render(this.props)
}
NewComponent.prototype.ngOnInit = function () {
if (!this.comp.element) {
var el = this.comp.render(this.props)
this.node.appendChild(el)
}
}
return NewComponent
};