Console.js 1.1 KB

12345678910
  1. import{ObjectWrapper}from'./Object.js';export class Console extends ObjectWrapper{constructor(){super();this._messages=[];}
  2. addMessage(text,level,show){const message=new Message(text,level||MessageLevel.Info,Date.now(),show||false);this._messages.push(message);this.dispatchEventToListeners(Events.MessageAdded,message);}
  3. log(text){this.addMessage(text,MessageLevel.Info);}
  4. warn(text){this.addMessage(text,MessageLevel.Warning);}
  5. error(text){this.addMessage(text,MessageLevel.Error,true);}
  6. messages(){return this._messages;}
  7. show(){this.showPromise();}
  8. showPromise(){return Common.Revealer.reveal(this);}}
  9. export const Events={MessageAdded:Symbol('messageAdded')};export const MessageLevel={Info:'info',Warning:'warning',Error:'error'};export class Message{constructor(text,level,timestamp,show){this.text=text;this.level=level;this.timestamp=(typeof timestamp==='number')?timestamp:Date.now();this.show=show;}}
  10. self.Common=self.Common||{};Common=Common||{};Common.console=new Console();Common.Console=Console;Common.Console.Events=Events;Common.Console.MessageLevel=MessageLevel;Common.Console.Message=Message;