All files / core View.ts

100% Statements 11/11
100% Branches 7/7
100% Functions 3/3
100% Lines 11/11
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                      1x 1x 4x 3x 6x 6x 2x     3x     1x       1x       1x  
abstract class View {
 
  /**
   * Data inserted into the view via constructor.
   */
  public data: any;
 
  /**
   * Yields all methods (i.e., content type handlers) of the view instance. 
   */
  public *methods() {
    const obj = this;
    const getProps = function* (object) {
      if (object !== Object.prototype) {
        for (let name of Object.getOwnPropertyNames(object)) {
          const fn = object[name];
          if (fn instanceof Function && name !== 'constructor' && name !== 'methods') {
            yield name;
          }
        }
        yield* getProps(Object.getPrototypeOf(object));
      }
    };
    yield* getProps(obj);
  }
 
  constructor(data?: any) {
    this.data = data;
  }
}
 
export { View as default };