31 lines
963 B
JavaScript
31 lines
963 B
JavaScript
import { CmapAppearance } from "./appearance.js";
|
|
|
|
/**
|
|
* Persist wiki-wide CMap appearance through the backend.
|
|
* Styles and the colour palette form one appearance aggregate.
|
|
*/
|
|
export class CmapAppearanceRepository {
|
|
constructor(api) {
|
|
if (typeof api !== "function") throw new TypeError("A wiki API function is required");
|
|
this.api = api;
|
|
}
|
|
|
|
/** Load and deserialize the complete wiki-wide appearance aggregate. */
|
|
async load() {
|
|
const result = await this.api("/api/cmap-appearance");
|
|
return new CmapAppearance(result);
|
|
}
|
|
|
|
/** Persist one appearance aggregate and refresh it with backend normalization. */
|
|
async save(appearance) {
|
|
if (!(appearance instanceof CmapAppearance)) {
|
|
throw new TypeError("A CmapAppearance is required");
|
|
}
|
|
const result = await this.api("/api/cmap-appearance", {
|
|
method: "PUT",
|
|
body: JSON.stringify(appearance.toData())
|
|
});
|
|
return appearance.replace(result);
|
|
}
|
|
}
|