UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

33 lines (32 loc) 1.1 kB
import { TimeContextFilter } from "./TimeContextFilter.js"; /** * Cache cases which were already fetched, and filter out cases in memory according to (time) context. */ export class AbstractDatasource { constructor(authors, copyright) { this.authors = authors; this.copyright = copyright; this.cases = new Map(); } async getCases(context) { const contextKey = this.contextKey(context); let found = this.cases.get(contextKey); if (!found) { found = await this.readCases(context); this.cases.set(contextKey, found); } return found; } async fetch(context) { const summaries = await this.getCases(context); // TODO: This filter can only apply to RROUfoCases[], not S[] const contextFilter = this.createFilter(context); return summaries.filter(contextFilter.filter.bind(contextFilter)); } createFilter(context) { return new TimeContextFilter(context); // By default } contextKey(context) { return context.time.toString(); } }