ts-mixins

Basic implementation of http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/ in typescript

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
ts-mixins
1.0.07 years ago7 years agoMinified + gzip package size for ts-mixins in KB

Readme

ts-mixins
Implementation of also inspired by and Instead of using Object.assign or native typescript mixins, its using a custom mix function that does not call PropertyDescriptors(get/set) and applies the whole prototype chain to the mixedclass allowing for mixin classes to extend other classes ```typescript import {Mixin} from "@nan0c@ts-mixins"; export class One {
constructor(){}
public logO():void{
console.log('ONE');
}
} export class BaseTwo {
public logO():void{
console.log('BASE_TWO');
}
} export class Two extends BaseTwo{
constructor(){
super();
}
public logO():void{
super.logO();
console.log('TWO');
}
} export class Three extends Two {
constructor(){
super();
}
public logO():void{
super.logO();
console.log('THREE');
}
} export interface IThreeOne extends Three,One{} export class ThreeOne extends Mixin(Three,One) {
constructor(){
super();
}
public logO():void{
super.logO();
console.log('THREE_ONE');
}
} export class OneThree extends Mixin(One,Three) {
constructor(){
super();
}
public logO():void{
super.logO();
console.log('ONE_THREE');
}
} let threeOne = new ThreeOne(); threeOne.logO(); / Will print
THREE_ONE 
BASE_TWO 
TWO
THREE
/ let oneThree = new OneThree(); oneThree.logO(); / Will print
ONE
ONE_THREE
/ ```