Last active
November 30, 2017 21:16
-
-
Save lifeart/48fe5df4321c1f00ec1df9c4d5955802 to your computer and use it in GitHub Desktop.
Angular 1.5.8 ES6 modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AngularComponent { | |
constructor(...args) { | |
this.setupComponent(args); | |
} | |
setupComponent(args) { | |
console.log('setupComponent', args); | |
} | |
static ngConstruct() { | |
const instance = new this(); | |
return { | |
bindings: instance.bindings, | |
template: instance.template, | |
transclude: instance.transclude, | |
templateUrl: instance.templateUrl, | |
controller: instance.controller ? instance.controller.ngConstruct() : undefined | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AngularController { | |
static injections() { | |
return []; | |
} | |
static ngConstruct() { | |
return [...this.injections().map(el=>el.split(':').pop()), this]; | |
} | |
constructor(...args) { | |
this.constructor.injections().forEach((el, index) => this._defineKey(el, args[index])); | |
this.setupController(args); | |
} | |
_defineKey(key, value) { | |
Object.defineProperty(this, key.split(':')[0], {enumerable: true, value}); | |
} | |
setupController(args) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AngularDirective { | |
static injections() { | |
return []; | |
} | |
static ngConstruct() { | |
return [...this.injections().map(el=>el.split(':').pop()), this._init.bind(this)]; | |
} | |
static _init(...argumentsList) { | |
const _this = this; | |
return (function (argumentsList) { | |
return new _this(...argumentsList); | |
})(argumentsList); | |
} | |
constructor(...args) { | |
this.constructor.injections().forEach((el, index) => this._defineKey(el, args[index])); | |
this.setupDirective(args); | |
return this; | |
} | |
setupDirective(args) { | |
throw new Error('Unable to find "setupDirective" method for ES6 directive class',args); | |
} | |
_defineKey(key, value) { | |
Object.defineProperty(this, key.split(':')[0], {enumerable: true, value}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AngularService { | |
static injections() { | |
return []; | |
} | |
static ngConstruct() { | |
return [...this.injections().map(el=>el.split(':').pop()), this]; | |
} | |
static _init() { | |
const argumentsList = Array.prototype.slice.call(arguments,0); | |
return (Function.prototype.bind.apply(this, [null].concat(argumentsList))); | |
} | |
constructor(...args) { | |
this.constructor.injections().forEach((el, index) => this._defineKey(el, args[index])); | |
this.setupService(args); | |
} | |
_defineKey(key, value) { | |
Object.defineProperty(this, key.split(':')[0], {enumerable: true, value}); | |
} | |
setupService(args) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AngularState { | |
static injections() { | |
return []; | |
} | |
static ngConstruct() { | |
return [...this.injections().map(el=>el.split(':').pop()), this._init.bind(this)]; | |
} | |
static _init() { | |
const argumentsList = Array.prototype.slice.call(arguments,0); | |
return new this(...argumentsList); | |
} | |
constructor(...args) { | |
this.constructor.injections().forEach((el, index) => this._defineKey(el, args[index])); | |
this.setupState(args); | |
} | |
_defineKey(key, value) { | |
Object.defineProperty(this, key.split(':')[0], {enumerable: true, value}); | |
} | |
setupState(args) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment