[一起來學習篇] RxJS / decorator / graphql

  1. rxjs: zip+combineLatest, 與 decorator
    https://youtu.be/EbdxbsrwUqI

  2. graphql 後端實作的方法與觀念
    https://youtu.be/peNdqITwSck

連結分享

  1. https://gist.github.com/remojansen/16c661a7afd68e22ac6e
  2. http://blog.wolksoftware.com/decorators-reflection-javascript-typescript
1個讚

typescript內的decorator如果用這樣子寫法,就可以做到 mixin 的效果

function logClass(target: any) {
  // save a reference to the original constructor
  var original = target;

  // a utility function to generate instances of a class
  function construct(constructor, args) {
    var c: any = function() {
      return constructor.apply(this, args);
    };
    c.prototype = constructor.prototype;
    return new c();
  }

  // the new constructor behaviour
  var f: any = function(...args) {
    console.log('New: ' + original.name);
    return construct(original, args);
  };

  // copy prototype so intanceof operator still works
  f.prototype = original.prototype;
  f.prototype.log = () => {
    return 'log功能實作'
  };
  // return new constructor (will override original)
  return f;
}

interface logger {
  log: () => string;
}

@logClass
class Person implements logger {
  log: () => string;
  public name: string;
  public surname: string;

  constructor(name: string, surname: string) {
    this.name = name;
    this.surname = surname;
  }
}
var p = new Person('remo', 'jansen');
console.log(p.log()); //return log功能實作

提供給大家參考看看