slight optimizations to chatview template variable

This commit is contained in:
nova 2019-12-10 19:50:15 +05:30
parent b83417570d
commit 849a5133d7
2 changed files with 3 additions and 10 deletions

View File

@ -12,12 +12,10 @@ import { SJCLEncryptionService } from "../service/SJCLEncryptionService";
import { EncryptionService } from "../service/EncryptionService"; import { EncryptionService } from "../service/EncryptionService";
import { ChatMessageDTO } from "../dto/ChatMessageDTO"; import { ChatMessageDTO } from "../dto/ChatMessageDTO";
import { fetchHandler } from "./FetchHandler"; import { fetchHandler } from "./FetchHandler";
// var md = new markdownit();
export class ChatView implements Observer { export class ChatView implements Observer {
private readonly _chatModel: ChatModel; private readonly _chatModel: ChatModel;
private readonly _messageContainer: HTMLElement; private readonly _messageContainer: HTMLElement;
// private readonly _messageSendButton: HTMLElement;
private readonly _messageSendTemplate = TemplateFactory.getTemplate('msg_container_send_template'); private readonly _messageSendTemplate = TemplateFactory.getTemplate('msg_container_send_template');
private readonly _messageReceiveTemplate = TemplateFactory.getTemplate('msg_container_template'); private readonly _messageReceiveTemplate = TemplateFactory.getTemplate('msg_container_template');
private readonly _markdownService: MarkDownService = new MarkDownItMarkDownService(); private readonly _markdownService: MarkDownService = new MarkDownItMarkDownService();
@ -27,7 +25,6 @@ export class ChatView implements Observer {
constructor(chatModel: ChatModel, messageContainer: HTMLElement) { constructor(chatModel: ChatModel, messageContainer: HTMLElement) {
this._messageContainer = messageContainer; this._messageContainer = messageContainer;
this._chatModel = chatModel; this._chatModel = chatModel;
// this._messageSendButton = messageSendButton;
this.addEventListeners(); this.addEventListeners();
} }

View File

@ -20,8 +20,8 @@ export class UserView implements Observer {
private readonly _userSearchButton: HTMLElement; private readonly _userSearchButton: HTMLElement;
private readonly _userSearchCancelButton: HTMLElement; private readonly _userSearchCancelButton: HTMLElement;
private readonly _searchService: SearchService<ActiveUserViewModel>; private readonly _searchService: SearchService<ActiveUserViewModel>;
// private userBoxes: any[] = []; private readonly _userContactOnlineTemplate: Handlebars.TemplateDelegate<ActiveUserViewModel> = TemplateFactory.getTemplate('user-contact-online-template');
private readonly _userContactOfflineTemplate: Handlebars.TemplateDelegate<ActiveUserViewModel> = TemplateFactory.getTemplate('user-contact-offline-template');
constructor(model: UserModel, chatModel: ChatModel, usersListElement: HTMLElement, constructor(model: UserModel, chatModel: ChatModel, usersListElement: HTMLElement,
userSearchInputElement: HTMLInputElement, userSearchButton: HTMLElement, userSearchCancelButton: HTMLElement) { userSearchInputElement: HTMLInputElement, userSearchButton: HTMLElement, userSearchCancelButton: HTMLElement) {
@ -36,15 +36,11 @@ export class UserView implements Observer {
this.addSearchEventListeners(); this.addSearchEventListeners();
} }
update(data: ActiveUserViewModel[]): void { update(data: ActiveUserViewModel[]): void {
let template = TemplateFactory.getTemplate('user-contact-online-template');
let html: string = ""; let html: string = "";
data.forEach((element: ActiveUserViewModel) => { data.forEach((element: ActiveUserViewModel) => {
html += template(element); element.online ? html+=this._userContactOnlineTemplate(element) : html+=this._userContactOfflineTemplate(element);
}); });
// this._element.innerHTML = html;
$(this._usersListElement).html(DOMPurify.sanitize(html)); $(this._usersListElement).html(DOMPurify.sanitize(html));
this.addUserCallBacks(); this.addUserCallBacks();
console.log(this._usersListElement.innerHTML); console.log(this._usersListElement.innerHTML);