UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

135 lines (118 loc) 2.75 kB
/** * Copyright © Volker Schukai and all contributing authors, {{copyRightYear}}. All rights reserved. * Node module: @schukai/monster * * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3). * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html * * For those who do not wish to adhere to the AGPLv3, a commercial license is available. * Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms. * For more information about purchasing a commercial license, please contact Volker Schukai. * * SPDX-License-Identifier: AGPL-3.0 */ import { Base } from "../../../types/base.mjs"; import { equipWithInternal } from "../../../types/internal.mjs"; import { instanceSymbol } from "../../../constants.mjs"; import { Observer } from "../../../types/observer.mjs"; import { isInstance } from "../../../types/is.mjs"; export { Entry }; /** * The Entry class represents a single entry in a log. * * @copyright Volker Schukai * @summary A single entry in a log. */ class Entry extends Base { constructor({ title, message, user, date } = {}) { super(); /** * - attachInternalObserver * - detachInternalObserver * - containsInternalObserver * - setInternal * - setInternals * - getInternal */ equipWithInternal.call(this); if (title) this.title = title; if (message) this.message = message; if (user) this.user = user; if (date) this.date = date; this.attachInternalObserver( new Observer(() => { //updateStruct.call(self); }), ); } /** * This method is called by the `instanceof` operator. * @return {symbol} */ static get [instanceSymbol]() { return Symbol.for("@schukai/component-state/log/entry"); } /** * * @return {object} */ get internalDefaults() { return { title: null, message: null, user: null, date: null, }; } /** * @return {string} */ get title() { return this.getInternal("title"); } /** * @param {string} value */ set title(value) { this.setInternal("title", value); } /** * @return {string} */ get message() { return this.getInternal("message"); } /** * @param {string} value */ set message(value) { this.setInternal("message", value); } /** * @return {string} */ get user() { return this.getInternal("user"); } /** * @param {string} value */ set user(value) { this.setInternal("user", value); } /** * @return {Date} */ get date() { return this.getInternal("date"); } /** * @param {string|Date} value */ set date(value) { if (!isInstance(value, Date)) { value = new Date(value); } this.setInternal("date", value); } }