122 lines
1.9 KiB
JavaScript
122 lines
1.9 KiB
JavaScript
/*
|
|
Copyright (c) 2023-forever Douglas Malnati. All rights reserved.
|
|
|
|
See the /faq/tos page for details.
|
|
|
|
(If this generated header is stamped on a file which is a 3rd party file or under a different license or copyright, then ignore this copyright statement and use that file's terms.)
|
|
*/
|
|
|
|
import * as utl from './Utl.js';
|
|
|
|
|
|
// fold this functionality back into the original Event.js later
|
|
class Event
|
|
{
|
|
static handlerList = [];
|
|
|
|
AddHandler(handler)
|
|
{
|
|
Event.handlerList.push(handler);
|
|
}
|
|
|
|
Emit(evt)
|
|
{
|
|
if (typeof(evt) == "string")
|
|
{
|
|
evt = {
|
|
type: evt
|
|
};
|
|
}
|
|
|
|
for (const evtHandler of Event.handlerList)
|
|
{
|
|
if (evtHandler.OnEvent)
|
|
{
|
|
evtHandler.OnEvent(evt);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
export class Base
|
|
extends Event
|
|
{
|
|
static globalDebugAnyway = false;
|
|
|
|
constructor(t)
|
|
{
|
|
super();
|
|
|
|
this.AddHandler(this);
|
|
|
|
// timeline
|
|
this.t = null;
|
|
|
|
|
|
//
|
|
// logging levels
|
|
//
|
|
|
|
// debug
|
|
this.debug = false;
|
|
|
|
// info
|
|
this.info = true;
|
|
}
|
|
|
|
// only to be called once, from main application, when everything is
|
|
// constructed and ready to go
|
|
Run()
|
|
{
|
|
urlStateProxy.OnPageLoad();
|
|
}
|
|
|
|
SetDebug(tf)
|
|
{
|
|
this.debug = tf;
|
|
}
|
|
|
|
SetGlobalDebug(tf)
|
|
{
|
|
Base.globalDebugAnyway = tf;
|
|
}
|
|
|
|
Debug(str)
|
|
{
|
|
if (this.debug || Base.globalDebugAnyway)
|
|
{
|
|
console.log(str);
|
|
}
|
|
}
|
|
|
|
DebugTable(val)
|
|
{
|
|
if (this.debug || Base.globalDebugAnyway)
|
|
{
|
|
console.table(val);
|
|
}
|
|
}
|
|
|
|
SetInfo(tf)
|
|
{
|
|
this.info = tf;
|
|
}
|
|
|
|
Info(str)
|
|
{
|
|
if (this.info)
|
|
{
|
|
console.log(str);
|
|
}
|
|
}
|
|
|
|
Err(from, str)
|
|
{
|
|
console.log(`ERR: ${from} - ${str}`);
|
|
}
|
|
}
|
|
|
|
|
|
|