aboutsummaryrefslogtreecommitdiff
path: root/api/base.ts
blob: e89e76b38e064511ad35fa6c786373146bc88afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import Core from "../core/api.ts";
import Yomikun from "./yomikun.ts";

/** @summary generic class that keeps a reference to parent API reference */
export default abstract class APIBase {
  private _resolveAPI: (api: Yomikun) => void = _ => {};

  protected api: Promise<Yomikun>;

  constructor() {
    this.api = new Promise<Yomikun>(res => this._resolveAPI = res);
  }
  
  /** @summary set API reference and return self (for use directly after constructor) */
  withParent(api: Yomikun) {
    this._resolveAPI(api);
    return this;
  }
}