Skip to content

Instantly share code, notes, and snippets.

@lifeart
Last active November 30, 2017 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeart/48fe5df4321c1f00ec1df9c4d5955802 to your computer and use it in GitHub Desktop.
Save lifeart/48fe5df4321c1f00ec1df9c4d5955802 to your computer and use it in GitHub Desktop.
Angular 1.5.8 ES6 modules
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
};
}
}
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) {
}
}
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});
}
}
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) {
}
}
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