"use strict"; import {Common} from "../Utils/Common.ecma.js"; /** * @typedef {import("../AnP.ecma.js").AnP} AnP */ /** * @class ViewsManager * @constructor * @param {!AnP} anp * @return {void} * @access public * @static */ export const ViewsManager = (function(){ /** * @callback continue_callback * @param {!boolean} ok * @return {boolean} */ /** * @constructs ViewsManager * @param {!AnP} anp * @return {void} * @access private * @static */ const ViewsManager = function(anp){ /** @type {ViewsManager} */ const self = this, /** @type {Object.>} */ views = {}; /** @type {boolean} */ let started = false; /** * @returns {void} * @access private */ const constructor = () => {}; /** * @param {?continue_callback} callback * @returns {boolean} * @access public */ this.update = (callback = null) => { Common.execute_array(["default_views_files", "views_files", "default_views", "views"], (key, next) => { self.add(self.get(key), true, next); }, callback, true); }; /** * @param {?continue_callback} callback * @returns {boolean} * @access public */ this.reset = (callback = null) => { Common.clear_dictionary(views); self.update(callback); }; /** * @param {?continue_callback} callback * @returns {boolean} * @access public */ this.start = (callback = null) => { /** @type {continue_callback} */ const end = ok => Common.execute(callback, ok); if(started){ end(false); return false; }; started = true; self.update(() => end(true)); return true; }; /** * @param {?continue_callback} callback * @returns {boolean} * @access public */ this.close = (callback = null) => { /** @type {continue_callback} */ const end = ok => Common.execute(callback, ok); if(!started){ end(false); return false; }; started = false; end(true); return true; }; /** * @param {?(Object.|Array.)} inputs * @param {!boolean} [overwrite = false] * @param {?continue_callback} [callback = null] * @return {void} * @access public */ this.add = (inputs, overwrite = false, callback = null) => { anp.files.load_json(inputs, data => { data.forEach(set => { Object.entries(set).forEach(([key, value]) => { if(overwrite || !views[key]) views[key] = value; }); }); Common.execute(callback, true); }, true); }; this.get = (key, inputs = null) => {}; constructor(); }; return ViewsManager; })();