import autobind from 'autobind-decorator'; import Chart, { Obj, DeepPartial } from '../core'; import { SchemaType } from '@/misc/schema'; import { name, schema } from './entities/test'; type TestLog = SchemaType; /** * For testing */ // eslint-disable-next-line import/no-default-export export default class TestChart extends Chart { public total = 0; // publicにするのはテストのため constructor() { super(name, schema); } @autobind protected genNewLog(latest: TestLog): DeepPartial { return { foo: { total: latest.foo.total, }, }; } @autobind protected aggregate(logs: TestLog[]): TestLog { return { foo: { total: logs[0].foo.total, inc: logs.reduce((a, b) => a + b.foo.inc, 0), dec: logs.reduce((a, b) => a + b.foo.dec, 0), }, }; } @autobind protected async fetchActual(): Promise> { return { foo: { total: this.total, }, }; } @autobind public async increment(): Promise { const update: Obj = {}; update.total = 1; update.inc = 1; this.total++; await this.inc({ foo: update, }); } @autobind public async decrement(): Promise { const update: Obj = {}; update.total = -1; update.dec = 1; this.total--; await this.inc({ foo: update, }); } }