Best JavaScript code snippet using wpt
main.component.ts
Source:main.component.ts
1import { Component, ComponentRef, NgZone, OnDestroy, Type, ViewChild, ViewContainerRef } from '@angular/core';2import { AvatarAction, HabboClubLevelEnum, IEventDispatcher, IRoomObject, Nitro, RoomEngineObjectEvent, RoomEnterEffect, RoomObjectCategory, RoomObjectType, RoomObjectUserType, RoomObjectVariable, RoomUserData } from '@nitrots/nitro-renderer';3import { SettingsService } from '../../../../../../core/settings/service';4import { AvatarEditorService } from '../../../../../avatar-editor/services/avatar-editor.service';5import { FriendListService } from '../../../../../friendlist/services/friendlist.service';6import { ContextInfoView } from '../../../contextmenu/ContextInfoView';7import { IContextMenuParentWidget } from '../../../contextmenu/IContextMenuParentWidget';8import { ConversionTrackingWidget } from '../../../ConversionTrackingWidget';9import { RoomObjectNameEvent } from '../../../events/RoomObjectNameEvent';10import { RoomWidgetAvatarInfoEvent } from '../../../events/RoomWidgetAvatarInfoEvent';11import { RoomWidgetFurniInfostandUpdateEvent } from '../../../events/RoomWidgetFurniInfostandUpdateEvent';12import { RoomWidgetPetInfostandUpdateEvent } from '../../../events/RoomWidgetPetInfostandUpdateEvent';13import { RoomWidgetRentableBotInfostandUpdateEvent } from '../../../events/RoomWidgetRentableBotInfostandUpdateEvent';14import { RoomWidgetRoomEngineUpdateEvent } from '../../../events/RoomWidgetRoomEngineUpdateEvent';15import { RoomWidgetRoomObjectUpdateEvent } from '../../../events/RoomWidgetRoomObjectUpdateEvent';16import { RoomWidgetUpdateInfostandUserEvent } from '../../../events/RoomWidgetUpdateInfostandUserEvent';17import { RoomWidgetUserDataUpdateEvent } from '../../../events/RoomWidgetUserDataUpdateEvent';18import { RoomWidgetUserLocationUpdateEvent } from '../../../events/RoomWidgetUserLocationUpdateEvent';19import { AvatarInfoWidgetHandler } from '../../../handlers/AvatarInfoWidgetHandler';20import { RoomWidgetGetObjectLocationMessage } from '../../../messages/RoomWidgetGetObjectLocationMessage';21import { RoomWidgetRoomObjectMessage } from '../../../messages/RoomWidgetRoomObjectMessage';22import { RoomWidgetUpdateEvent } from '../../../RoomWidgetUpdateEvent';23import { AvatarContextInfoView } from '../../common/AvatarContextInfoView';24import { AvatarInfoData } from '../../common/AvatarInfoData';25import { PetInfoData } from '../../common/PetInfoData';26import { RentableBotInfoData } from '../../common/RentableBotInfoData';27import { RoomAvatarInfoAvatarComponent } from '../avatar/avatar.component';28import { RoomAvatarInfoDecorateComponent } from '../decorate/decorate.component';29import { RoomAvatarInfoNameComponent } from '../name/name.component';30import { RoomAvatarInfoOwnAvatarComponent } from '../ownavatar/ownavatar.component';31import { RoomAvatarInfoOwnPetComponent } from '../ownpet/ownpet.component';32import { RoomAvatarInfoPetComponent } from '../pet/pet.component';33import { RoomAvatarInfoRentableBotComponent } from '../rentablebot/rentablebot.component';34@Component({35 selector: 'nitro-room-avatarinfo-component',36 templateUrl: './main.template.html'37})38export class RoomAvatarInfoComponent extends ConversionTrackingWidget implements IContextMenuParentWidget, OnDestroy39{40 private static _Str_17951: number = 77;41 private static _Str_18968: number = 29;42 private static _Str_16970: number = 30;43 private static _Str_18857: number = 185;44 private static _Str_18641: number = 5000;45 @ViewChild('contextsContainer', { read: ViewContainerRef })46 public contextsContainer: ViewContainerRef;47 public view: ComponentRef<AvatarContextInfoView> = null;48 public cachedNameView: ComponentRef<RoomAvatarInfoNameComponent> = null;49 public cachedOwnAvatarMenuView: ComponentRef<RoomAvatarInfoOwnAvatarComponent> = null;50 public cachedAvatarMenuView: ComponentRef<RoomAvatarInfoAvatarComponent> = null;51 public cachedDecorateModeView: ComponentRef<RoomAvatarInfoDecorateComponent> = null;52 public cachedRentableBotMenuView: ComponentRef<RoomAvatarInfoRentableBotComponent> = null;53 public cachedPetMenuView: ComponentRef<RoomAvatarInfoPetComponent> = null;54 public cachedOwnPetMenuView: ComponentRef<RoomAvatarInfoOwnPetComponent> = null;55 public cachedNameBubbles: Map<string, ComponentRef<RoomAvatarInfoNameComponent>> = new Map();56 public lastRollOverId: number = -1;57 public userInfoData: AvatarInfoData = new AvatarInfoData();58 public petInfoData: PetInfoData = new PetInfoData();59 public rentableBotInfoData: RentableBotInfoData = new RentableBotInfoData();60 public isDancing: boolean = false;61 public handlePetInfo: boolean = true;62 private _isInitialized: boolean = false;63 private _isRoomEnteredOwnAvatarHighlight = false;64 private _isGameMode = false;65 private _isUpdating = false;66 constructor(67 private _avatarEditorService: AvatarEditorService,68 private _settingsService: SettingsService,69 private _friendListService: FriendListService,70 private _ngZone: NgZone71 )72 {73 super();74 this._Str_2557 = this._Str_2557.bind(this);75 this.onRoomEngineObjectEvent = this.onRoomEngineObjectEvent.bind(this);76 }77 public ngOnDestroy(): void78 {79 Nitro.instance.ticker.remove(this.update, this);80 }81 public registerUpdateEvents(eventDispatcher: IEventDispatcher): void82 {83 if(!eventDispatcher) return;84 Nitro.instance.roomEngine.events.addEventListener(RoomEngineObjectEvent.ADDED, this.onRoomEngineObjectEvent);85 Nitro.instance.roomEngine.events.addEventListener(RoomEngineObjectEvent.REMOVED, this.onRoomEngineObjectEvent);86 eventDispatcher.addEventListener(RoomWidgetAvatarInfoEvent.RWAIE_AVATAR_INFO, this._Str_2557);87 eventDispatcher.addEventListener(RoomObjectNameEvent.RWONE_TYPE, this._Str_2557);88 eventDispatcher.addEventListener(RoomWidgetUpdateInfostandUserEvent.OWN_USER, this._Str_2557);89 eventDispatcher.addEventListener(RoomWidgetUpdateInfostandUserEvent.PEER, this._Str_2557);90 eventDispatcher.addEventListener(RoomWidgetUserDataUpdateEvent.RWUDUE_USER_DATA_UPDATED, this._Str_2557);91 eventDispatcher.addEventListener(RoomWidgetRoomObjectUpdateEvent.USER_REMOVED, this._Str_2557);92 eventDispatcher.addEventListener(RoomWidgetFurniInfostandUpdateEvent.FURNI, this._Str_2557);93 eventDispatcher.addEventListener(RoomWidgetUpdateInfostandUserEvent.BOT, this._Str_2557);94 eventDispatcher.addEventListener(RoomWidgetRentableBotInfostandUpdateEvent.RENTABLE_BOT, this._Str_2557);95 eventDispatcher.addEventListener(RoomWidgetPetInfostandUpdateEvent.PET_INFO, this._Str_2557);96 eventDispatcher.addEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_SELECTED, this._Str_2557);97 eventDispatcher.addEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_DESELECTED, this._Str_2557);98 eventDispatcher.addEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OVER, this._Str_2557);99 eventDispatcher.addEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT, this._Str_2557);100 eventDispatcher.addEventListener(RoomWidgetRoomEngineUpdateEvent.RWREUE_NORMAL_MODE, this._Str_2557);101 eventDispatcher.addEventListener(RoomWidgetRoomEngineUpdateEvent.RWREUE_GAME_MODE, this._Str_2557);102 super.registerUpdateEvents(eventDispatcher);103 }104 public unregisterUpdateEvents(eventDispatcher: IEventDispatcher): void105 {106 if(!eventDispatcher) return;107 Nitro.instance.roomEngine.events.removeEventListener(RoomEngineObjectEvent.ADDED, this.onRoomEngineObjectEvent);108 Nitro.instance.roomEngine.events.removeEventListener(RoomEngineObjectEvent.REMOVED, this.onRoomEngineObjectEvent);109 eventDispatcher.removeEventListener(RoomWidgetAvatarInfoEvent.RWAIE_AVATAR_INFO, this._Str_2557);110 eventDispatcher.removeEventListener(RoomObjectNameEvent.RWONE_TYPE, this._Str_2557);111 eventDispatcher.removeEventListener(RoomWidgetUpdateInfostandUserEvent.OWN_USER, this._Str_2557);112 eventDispatcher.removeEventListener(RoomWidgetUpdateInfostandUserEvent.PEER, this._Str_2557);113 eventDispatcher.removeEventListener(RoomWidgetUserDataUpdateEvent.RWUDUE_USER_DATA_UPDATED, this._Str_2557);114 eventDispatcher.removeEventListener(RoomWidgetRoomObjectUpdateEvent.USER_REMOVED, this._Str_2557);115 eventDispatcher.removeEventListener(RoomWidgetFurniInfostandUpdateEvent.FURNI, this._Str_2557);116 eventDispatcher.removeEventListener(RoomWidgetUpdateInfostandUserEvent.BOT, this._Str_2557);117 eventDispatcher.removeEventListener(RoomWidgetRentableBotInfostandUpdateEvent.RENTABLE_BOT, this._Str_2557);118 eventDispatcher.removeEventListener(RoomWidgetPetInfostandUpdateEvent.PET_INFO, this._Str_2557);119 eventDispatcher.removeEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_SELECTED, this._Str_2557);120 eventDispatcher.removeEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_DESELECTED, this._Str_2557);121 eventDispatcher.removeEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OVER, this._Str_2557);122 eventDispatcher.removeEventListener(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT, this._Str_2557);123 eventDispatcher.removeEventListener(RoomWidgetRoomEngineUpdateEvent.RWREUE_NORMAL_MODE, this._Str_2557);124 eventDispatcher.removeEventListener(RoomWidgetRoomEngineUpdateEvent.RWREUE_GAME_MODE, this._Str_2557);125 super.unregisterUpdateEvents(eventDispatcher);126 }127 private onRoomEngineObjectEvent(event: RoomEngineObjectEvent): void128 {129 switch(event.type)130 {131 case RoomEngineObjectEvent.ADDED: {132 if(event.category !== RoomObjectCategory.UNIT) return;133 const userData = this.handler.roomSession.userDataManager.getUserDataByIndex(event.objectId);134 if(!userData) return;135 if(this._friendListService.getFriendNames().indexOf(userData.name) == -1) return;136 this.showFriendNameBubble(userData, event.objectId);137 return;138 }139 case RoomEngineObjectEvent.REMOVED: {140 if(event.category === RoomObjectCategory.UNIT)141 {142 for(const bubble of this.cachedNameBubbles.values())143 {144 if(bubble.instance.roomIndex === event.objectId) this.removeView(bubble, false);145 }146 }147 return;148 }149 }150 }151 private showFriendNameBubble(userData: RoomUserData, objectId: number): void152 {153 if(!userData) return;154 if(this.cachedNameBubbles.has(userData.name)) return;155 const view = this.createView(RoomAvatarInfoNameComponent);156 view.instance.isFriend = true;157 this._ngZone.run(() => RoomAvatarInfoNameComponent.setup(view.instance, userData.webID, userData.name, RoomObjectType.USER, objectId, true));158 this.cachedNameBubbles.set(userData.name, view);159 this.toggleUpdateReceiver();160 }161 private _Str_2557(event: RoomWidgetUpdateEvent): void162 {163 const viewInstance = ((this.view && this.view.instance) || null);164 switch(event.type)165 {166 case RoomWidgetAvatarInfoEvent.RWAIE_AVATAR_INFO: {167 const avatarInfoEvent = (event as RoomWidgetAvatarInfoEvent);168 this._isRoomEnteredOwnAvatarHighlight = (!this._isInitialized && this.handler.container.roomSession && (avatarInfoEvent._Str_2707 === this.handler.container.roomSession.ownRoomIndex));169 this._Str_12674(avatarInfoEvent.userId, avatarInfoEvent.userName, avatarInfoEvent._Str_2908, avatarInfoEvent._Str_2707, avatarInfoEvent._Str_4330, null);170 this._isInitialized = true;171 break;172 }173 case RoomObjectNameEvent.RWONE_TYPE: {174 const nameEvent = (event as RoomObjectNameEvent);175 if(nameEvent.category === RoomObjectCategory.UNIT)176 {177 this._Str_12674(nameEvent.userId, nameEvent.userName, nameEvent.userType, nameEvent.roomIndex, false, null);178 }179 break;180 }181 case RoomWidgetUpdateInfostandUserEvent.OWN_USER:182 case RoomWidgetUpdateInfostandUserEvent.PEER: {183 const infostandEvent = (event as RoomWidgetUpdateInfostandUserEvent);184 this.userInfoData.populate(infostandEvent);185 const userData = (infostandEvent.isSpectator ? null : this.userInfoData);186 this._Str_12674(infostandEvent.webID, infostandEvent.name, infostandEvent.userType, infostandEvent.roomIndex, false, userData);187 break;188 }189 case RoomWidgetPetInfostandUpdateEvent.PET_INFO: {190 if(this.handlePetInfo)191 {192 const infostandEvent = (event as RoomWidgetPetInfostandUpdateEvent);193 this.petInfoData.populate(infostandEvent);194 this._Str_24751(infostandEvent.id, infostandEvent.name, infostandEvent._Str_2707, this.petInfoData);195 }196 break;197 }198 case RoomWidgetRentableBotInfostandUpdateEvent.RENTABLE_BOT: {199 const infostandEvent = (event as RoomWidgetRentableBotInfostandUpdateEvent);200 if(!this.rentableBotInfoData) this.rentableBotInfoData = new RentableBotInfoData();201 this.rentableBotInfoData.populate(infostandEvent);202 const session = this.handler.container.roomSessionManager.getSession(0);203 if(!session) return;204 const userData = session.userDataManager.getRentableBotData(infostandEvent.id);205 if(!userData) return;206 if(this.rentableBotInfoData && userData.botSkills) this.rentableBotInfoData._Str_19891(userData.botSkills);207 this._Str_16991(infostandEvent.id, infostandEvent.name, infostandEvent.roomIndex, this.rentableBotInfoData);208 break;209 }210 case RoomWidgetUserDataUpdateEvent.RWUDUE_USER_DATA_UPDATED: {211 if(!this._isInitialized)212 {213 this._Str_25716();214 }215 break;216 }217 case RoomWidgetRoomObjectUpdateEvent.USER_REMOVED: {218 const removedEvent = (event as RoomWidgetRoomObjectUpdateEvent);219 if(viewInstance && ((viewInstance as AvatarContextInfoView).roomIndex === removedEvent.id)) this.removeView(this.view, false);220 for(const view of this.cachedNameBubbles.values())221 {222 const viewInstance = view.instance;223 if(viewInstance.roomIndex == removedEvent.id)224 {225 this.removeView(view, false);226 break;227 }228 }229 break;230 }231 case RoomWidgetFurniInfostandUpdateEvent.FURNI:232 if(this.view) this.removeView(this.view, false);233 break;234 case RoomWidgetRoomObjectUpdateEvent.OBJECT_SELECTED: {235 const selectedEvent = (event as RoomWidgetRoomObjectUpdateEvent);236 if(selectedEvent.category === RoomObjectCategory.UNIT)237 {238 this.handlePetInfo = true;239 }240 break;241 }242 case RoomWidgetRoomObjectUpdateEvent.OBJECT_DESELECTED:243 if(this.view) this.removeView(this.view, false);244 break;245 case RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OVER: {246 if(this._isRoomEnteredOwnAvatarHighlight) return;247 const rollOverEvent = (event as RoomWidgetRoomObjectUpdateEvent);248 if(!viewInstance || !((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent) || (viewInstance instanceof RoomAvatarInfoRentableBotComponent) || (viewInstance instanceof RoomAvatarInfoOwnPetComponent)))249 {250 this.lastRollOverId = rollOverEvent.id;251 this.messageListener.processWidgetMessage(new RoomWidgetRoomObjectMessage(RoomWidgetRoomObjectMessage.GET_OBJECT_NAME, rollOverEvent.id, rollOverEvent.category));252 }253 break;254 }255 case RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT: {256 if(this._isRoomEnteredOwnAvatarHighlight) return;257 const rollOutEvent = (event as RoomWidgetRoomObjectUpdateEvent);258 if(!viewInstance || !((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent) || (viewInstance instanceof RoomAvatarInfoRentableBotComponent) || (viewInstance instanceof RoomAvatarInfoOwnPetComponent)))259 {260 if(rollOutEvent.id === this.lastRollOverId)261 {262 this.removeView(this.view, false);263 this.lastRollOverId = -1;264 }265 }266 break;267 }268 case RoomWidgetRoomEngineUpdateEvent.RWREUE_NORMAL_MODE:269 this._isGameMode = false;270 break;271 case RoomWidgetRoomEngineUpdateEvent.RWREUE_GAME_MODE:272 this._isGameMode = true;273 break;274 }275 this.toggleUpdateReceiver();276 }277 private _Str_12674(userId: number, userName: string, userType: number, roomIndex: number, flag: boolean, avatarData: AvatarInfoData): void278 {279 const isAvatarMenu = !!avatarData;280 let viewInstance = (this.view && this.view.instance);281 if(isAvatarMenu && viewInstance)282 {283 if(!((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent) || (viewInstance instanceof RoomAvatarInfoPetComponent) || (viewInstance instanceof RoomAvatarInfoOwnPetComponent) || (viewInstance instanceof RoomAvatarInfoRentableBotComponent)))284 {285 this.removeView(this.view, false);286 viewInstance = null;287 }288 }289 if(!viewInstance || (viewInstance.userId !== userId) || (viewInstance.userName !== userName) || (viewInstance.userType !== userType) || (viewInstance.roomIndex !== roomIndex))290 {291 if(this.view) this.removeView(this.view, false);292 if(!this._isGameMode)293 {294 if(isAvatarMenu)295 {296 if(avatarData._Str_11453)297 {298 if(this.isDecorating) return;299 if(RoomEnterEffect.isRunning())300 {301 return;302 }303 else304 {305 if(!this.cachedOwnAvatarMenuView) this.cachedOwnAvatarMenuView = this.createView(RoomAvatarInfoOwnAvatarComponent);306 this.view = this.cachedOwnAvatarMenuView;307 this._ngZone.run(() => RoomAvatarInfoOwnAvatarComponent.setup((this.view.instance as RoomAvatarInfoOwnAvatarComponent), userId, userName, userType, roomIndex, avatarData));308 }309 }310 else311 {312 if(!this.cachedAvatarMenuView) this.cachedAvatarMenuView = this.createView(RoomAvatarInfoAvatarComponent);313 this.view = this.cachedAvatarMenuView;314 this._ngZone.run(() => RoomAvatarInfoAvatarComponent.setup((this.view.instance as RoomAvatarInfoAvatarComponent), userId, userName, userType, roomIndex, avatarData));315 for(const view of this.cachedNameBubbles.values())316 {317 const viewInstance = view.instance;318 if(viewInstance.userId !== userId) continue;319 this.removeView(view, false);320 break;321 }322 }323 }324 else325 {326 if(!this.handler.roomEngine.isDecorating)327 {328 if(!this.cachedNameView) this.cachedNameView = this.createView(RoomAvatarInfoNameComponent);329 this.view = this.cachedNameView;330 this._ngZone.run(() =>331 {332 if(this.handler.container.sessionDataManager.userId === userId)333 {334 this._ngZone.run(() => RoomAvatarInfoNameComponent.setup(this.view.instance, userId, userName, userType, roomIndex));335 if(this._isRoomEnteredOwnAvatarHighlight)336 {337 //338 }339 }340 else341 {342 this._ngZone.run(() => RoomAvatarInfoNameComponent.setup(this.view.instance, userId, userName, userType, roomIndex, true));343 }344 });345 }346 }347 }348 }349 else350 {351 if(viewInstance && ((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent)))352 {353 if(viewInstance.userId === userId) this.removeView(this.view, false);354 }355 }356 }357 private _Str_16991(userId: number, userName: string, roomIndex: number, avatarData: RentableBotInfoData): void358 {359 const isAvatarMenu = !!avatarData;360 let viewInstance = (this.view && this.view.instance);361 if(isAvatarMenu && viewInstance)362 {363 if(!((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent) || (viewInstance instanceof RoomAvatarInfoRentableBotComponent) || (viewInstance instanceof RoomAvatarInfoPetComponent) || (viewInstance instanceof RoomAvatarInfoOwnPetComponent)))364 {365 this.removeView(this.view, false);366 viewInstance = null;367 }368 }369 if(!viewInstance || (viewInstance.userId !== userId) || (viewInstance.userName !== userName) || (viewInstance.userType !== RoomObjectType.RENTABLE_BOT) || (viewInstance.roomIndex !== roomIndex))370 {371 if(this.view) this.removeView(this.view, false);372 if(!this._isGameMode)373 {374 if(isAvatarMenu)375 {376 if(!this.cachedRentableBotMenuView) this.cachedRentableBotMenuView = this.createView(RoomAvatarInfoRentableBotComponent);377 this.view = this.cachedRentableBotMenuView;378 this._ngZone.run(() => RoomAvatarInfoRentableBotComponent.setup((this.view.instance as RoomAvatarInfoRentableBotComponent), userId, userName, RoomObjectType.RENTABLE_BOT, roomIndex, avatarData));379 }380 }381 }382 else383 {384 if(viewInstance && (viewInstance instanceof RoomAvatarInfoRentableBotComponent))385 {386 if(viewInstance.userId === userId) this.removeView(this.view, false);387 }388 }389 }390 private _Str_24751(userId: number, userName: string, roomIndex: number, avatarData: PetInfoData): void391 {392 const isAvatarMenu = !!avatarData;393 let viewInstance = (this.view && this.view.instance);394 if(isAvatarMenu && viewInstance)395 {396 if(!((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent) || (viewInstance instanceof RoomAvatarInfoPetComponent) || (viewInstance instanceof RoomAvatarInfoOwnPetComponent) || (viewInstance instanceof RoomAvatarInfoRentableBotComponent)))397 {398 this.removeView(this.view, false);399 viewInstance = null;400 }401 }402 if(!viewInstance || (viewInstance.userId !== userId) || (viewInstance.userName !== userName) || (viewInstance.userType !== RoomObjectType.PET) || (viewInstance.roomIndex !== roomIndex))403 {404 if(this.view) this.removeView(this.view, false);405 if(!this._isGameMode)406 {407 if(isAvatarMenu)408 {409 if(avatarData._Str_5175)410 {411 if(!this.cachedOwnPetMenuView) this.cachedOwnPetMenuView = this.createView(RoomAvatarInfoOwnPetComponent);412 this.view = this.cachedOwnPetMenuView;413 this._ngZone.run(() => RoomAvatarInfoOwnPetComponent.setup((this.view.instance as RoomAvatarInfoOwnPetComponent), userId, userName, RoomObjectType.PET, roomIndex, avatarData));414 }415 else416 {417 if(!this.cachedPetMenuView) this.cachedPetMenuView = this.createView(RoomAvatarInfoPetComponent);418 this.view = this.cachedPetMenuView;419 this._ngZone.run(() => RoomAvatarInfoPetComponent.setup((this.view.instance as RoomAvatarInfoPetComponent), userId, userName, RoomObjectType.PET, roomIndex, avatarData));420 }421 }422 }423 }424 else425 {426 if(viewInstance && ((viewInstance instanceof RoomAvatarInfoAvatarComponent) || (viewInstance instanceof RoomAvatarInfoOwnAvatarComponent)))427 {428 if(viewInstance.userId === userId) this.removeView(this.view, false);429 }430 }431 }432 private createView<T extends ContextInfoView>(component: Type<T>): ComponentRef<T>433 {434 if(!component) return null;435 let viewRef: ComponentRef<T> = null;436 let view: T = null;437 this._ngZone.run(() =>438 {439 viewRef = this.contextsContainer.createComponent(component);440 view = viewRef.instance;441 });442 if(!view || !viewRef) return null;443 view.parent = this;444 view.componentRef = viewRef;445 return viewRef;446 }447 public close(): void448 {449 this.removeView(this.view, false);450 }451 public removeView(view: ComponentRef<ContextInfoView>, flag: boolean): void452 {453 this._isRoomEnteredOwnAvatarHighlight = false;454 if(!view) return;455 const componentIndex = this.contextsContainer.indexOf(view.hostView);456 if(componentIndex === -1) return;457 this.cachedNameView = null;458 this.cachedOwnAvatarMenuView = null;459 this.cachedAvatarMenuView = null;460 this.cachedRentableBotMenuView = null;461 this.cachedPetMenuView = null;462 this.cachedOwnPetMenuView = null;463 if(view === this.view) this.view = null;464 if(view instanceof RoomAvatarInfoNameComponent)465 {466 this.cachedNameBubbles.delete((view.instance as RoomAvatarInfoNameComponent).userName);467 this.toggleUpdateReceiver();468 }469 this._ngZone.run(() => this.contextsContainer.remove(componentIndex));470 }471 public toggleUpdateReceiver(): void472 {473 if(this.view || (this.cachedNameBubbles.size > 0) || this.cachedDecorateModeView)474 {475 if(this._isUpdating) return;476 Nitro.instance.ticker.add(this.update, this);477 this._isUpdating = true;478 }479 else480 {481 Nitro.instance.ticker.remove(this.update, this);482 this._isUpdating = false;483 }484 }485 public update(time: number): void486 {487 if(this.view)488 {489 const viewInstance = this.view.instance;490 const message = (this.messageListener.processWidgetMessage(new RoomWidgetGetObjectLocationMessage(RoomWidgetGetObjectLocationMessage.RWGOI_MESSAGE_GET_OBJECT_LOCATION, viewInstance.userId, viewInstance.userType)) as RoomWidgetUserLocationUpdateEvent);491 if(message) viewInstance.update(message.rectangle, message._Str_9337, time);492 }493 if(this.cachedDecorateModeView)494 {495 const viewInstance = this.cachedDecorateModeView.instance;496 const message = (this.messageListener.processWidgetMessage(new RoomWidgetGetObjectLocationMessage(RoomWidgetGetObjectLocationMessage.RWGOI_MESSAGE_GET_OBJECT_LOCATION, viewInstance.userId, viewInstance.userType)) as RoomWidgetUserLocationUpdateEvent);497 if(message) viewInstance.update(message.rectangle, message._Str_9337, time);498 }499 for(const view of this.cachedNameBubbles.values())500 {501 if(!view) continue;502 const viewInstance = view.instance;503 const message = (this.messageListener.processWidgetMessage(new RoomWidgetGetObjectLocationMessage(RoomWidgetGetObjectLocationMessage.RWGOI_MESSAGE_GET_OBJECT_LOCATION, viewInstance.userId, viewInstance.userType)) as RoomWidgetUserLocationUpdateEvent);504 if(message) viewInstance.update(message.rectangle, message._Str_9337, time);505 }506 }507 private getOwnRoomObject(): IRoomObject508 {509 const userId = this.handler.container.sessionDataManager.userId;510 const roomId = this.handler.roomEngine.activeRoomId;511 const category = RoomObjectCategory.UNIT;512 const totalObjects = this.handler.roomEngine.getTotalObjectsForManager(roomId, category);513 let i = 0;514 while(i < totalObjects)515 {516 const roomObject = this.handler.roomEngine.getRoomObjectByIndex(roomId, i, category);517 if(roomObject)518 {519 const userData = this.handler.roomSession.userDataManager.getUserDataByIndex(roomObject.id);520 if(userData)521 {522 if(userData.webID === userId) return roomObject;523 }524 }525 i++;526 }527 return null;528 }529 private _Str_25716(): void530 {531 this.messageListener.processWidgetMessage(new RoomWidgetRoomObjectMessage(RoomWidgetRoomObjectMessage.GET_OWN_CHARACTER_INFO, 0, 0));532 }533 public openAvatarEditor(): void534 {535 this._avatarEditorService.loadOwnAvatarInEditor();536 this._settingsService.showAvatarEditor();537 }538 public useSign(sign: number): void539 {540 this.widgetHandler.container.roomSession.sendSignMessage(sign);541 }542 public get getOwnPosture(): string543 {544 const roomObject = this.getOwnRoomObject();545 if(roomObject)546 {547 const model = roomObject.model;548 if(model)549 {550 return model.getValue<string>(RoomObjectVariable.FIGURE_POSTURE);551 }552 }553 return AvatarAction.POSTURE_STAND;554 }555 public get getCanStandUp(): boolean556 {557 const roomObject = this.getOwnRoomObject();558 if(roomObject)559 {560 const model = roomObject.model;561 if(model)562 {563 return model.getValue<boolean>(RoomObjectVariable.FIGURE_CAN_STAND_UP);564 }565 }566 return false;567 }568 public get _Str_12708(): boolean569 {570 const roomObject = this.getOwnRoomObject();571 if(roomObject)572 {573 const model = roomObject.model;574 if(model)575 {576 const effectId = model.getValue<number>(RoomObjectVariable.FIGURE_EFFECT);577 return ((effectId === RoomAvatarInfoComponent._Str_18968) || (effectId === RoomAvatarInfoComponent._Str_16970) || (effectId === RoomAvatarInfoComponent._Str_18857));578 }579 }580 return false;581 }582 public get _Str_25831(): boolean583 {584 const roomObject = this.getOwnRoomObject();585 if(roomObject)586 {587 const model = roomObject.model;588 if(model)589 {590 const effectId = model.getValue<number>(RoomObjectVariable.FIGURE_EFFECT);591 return (effectId === RoomAvatarInfoComponent._Str_17951);592 }593 }594 return false;595 }596 public get handler(): AvatarInfoWidgetHandler597 {598 return (this.widgetHandler as AvatarInfoWidgetHandler);599 }600 public get isDecorating(): boolean601 {602 return this.handler.roomSession.isDecorating;603 }604 public set isDecorating(flag: boolean)605 {606 this.handler.roomSession.isDecorating = flag;607 if(flag)608 {609 if(!this.cachedDecorateModeView) this.cachedDecorateModeView = this.createView(RoomAvatarInfoDecorateComponent);610 const userId = this.handler.container.sessionDataManager.userId;611 const userName = this.handler.container.sessionDataManager.userName;612 const roomIndex = this.handler.roomSession.ownRoomIndex;613 RoomAvatarInfoDecorateComponent.setup(this.cachedDecorateModeView.instance, userId, userName, RoomObjectUserType.getTypeNumber(RoomObjectUserType.USER), roomIndex);614 }615 else616 {617 if(this.cachedDecorateModeView)618 {619 this.removeView(this.cachedDecorateModeView, false);620 this.cachedDecorateModeView = null;621 }622 }623 }624 public get hasClub(): boolean625 {626 return (this.handler.container.sessionDataManager.clubLevel >= HabboClubLevelEnum.CLUB);627 }628 public get hasVip(): boolean629 {630 return (this.handler.container.sessionDataManager.clubLevel >= HabboClubLevelEnum.VIP);631 }...
view.test.ts
Source:view.test.ts
1import testMobx from './mobx';2import { Collection, Model, View, Attribute } from '../src';3import { updateModelId } from '../src/helpers/model/fields';4import { ViewAttribute } from '../src/Attribute';5import { mobx } from '@datx/utils';6// @ts-ignore7testMobx.configure({ enforceActions: 'observed' });8describe('View', () => {9 it('should init a view', () => {10 const collection = new Collection();11 const viewInstance = new View('foo', collection);12 expect(viewInstance).toBeInstanceOf(View);13 });14 it('should be able to get initial models', () => {15 class Foo extends Model {16 public static type = 'foo';17 }18 class AppCollection extends Collection {19 public static types = [Foo];20 }21 const collection = new AppCollection();22 const foos = collection.add([{}, {}], Foo);23 const viewInstance = new View(Foo, collection, undefined, [-1, -2]);24 expect(viewInstance).toHaveLength(2);25 expect(viewInstance.list[0]).toBeInstanceOf(Foo);26 expect(viewInstance.list[1]).toBeInstanceOf(Foo);27 expect(viewInstance.list[0]).toBe(foos[0]);28 expect(viewInstance.hasItem(foos[1])).toBe(true);29 });30 it('should be able to receive models', () => {31 class Foo extends Model {32 public static type = 'foo';33 }34 class AppCollection extends Collection {35 public static types = [Foo];36 }37 const collection = new AppCollection();38 const foos = collection.add([{}, {}], Foo);39 const viewInstance = new View(Foo, collection);40 viewInstance.add(foos);41 expect(viewInstance).toHaveLength(2);42 expect(viewInstance.list[0]).toBeInstanceOf(Foo);43 expect(viewInstance.list[1]).toBeInstanceOf(Foo);44 expect(viewInstance.list[0]).toBe(foos[0]);45 });46 it('should be a dynamic list', () => {47 class Foo extends Model {48 public static type = 'foo';49 }50 class AppCollection extends Collection {51 public static types = [Foo];52 }53 const collection = new AppCollection();54 const foos = collection.add([{}, {}], Foo);55 const viewInstance = new View(Foo, collection);56 let expectedLength = 0;57 let lengthAutorunCount = 0;58 let listAutorunCount = 0;59 testMobx.autorun(() => {60 expect(viewInstance).toHaveLength(expectedLength);61 lengthAutorunCount++;62 });63 testMobx.autorun(() => {64 expect(viewInstance.list).toHaveLength(expectedLength);65 listAutorunCount++;66 });67 expectedLength = foos.length;68 viewInstance.add(foos);69 expect(viewInstance).toHaveLength(2);70 expect(viewInstance.list[0]).toBeInstanceOf(Foo);71 expect(viewInstance.list[1]).toBeInstanceOf(Foo);72 expect(viewInstance.list[0]).toBe(foos[0]);73 expect(listAutorunCount).toBe(mobx.useRealMobX ? 2 : 1);74 expect(lengthAutorunCount).toBe(mobx.useRealMobX ? 2 : 1);75 });76 it('should be able to sort models', () => {77 class Foo extends Model {78 public static type = 'foo';79 @Attribute()80 public key!: number;81 }82 class AppCollection extends Collection {83 public static types = [Foo];84 }85 const collection = new AppCollection();86 const foos = collection.add([{ key: 2 }, { key: 3 }, { key: 1 }], Foo);87 const viewInstance = new View(Foo, collection, (item: Foo) => item.key, foos);88 expect(viewInstance).toHaveLength(3);89 const item0a = viewInstance.list[0];90 const item2a = viewInstance.list[2];91 expect(item0a && item0a.key).toBe(1);92 expect(item2a && item2a.key).toBe(3);93 const foo0 = collection.add({ key: 0 }, Foo);94 expect(viewInstance).toHaveLength(3);95 viewInstance.add(foo0);96 const item0b = viewInstance.list[0];97 const item2b = viewInstance.list[2];98 expect(item0b && item0b.key).toBe(0);99 expect(item2b && item2b.key).toBe(2);100 });101 it('should be able to sort models by non-numerical prop', () => {102 class Foo extends Model {103 public static type = 'foo';104 @Attribute()105 public key!: string;106 }107 class AppCollection extends Collection {108 public static types = [Foo];109 }110 const collection = new AppCollection();111 const foos = collection.add([{ key: 'abd' }, { key: 'bbf' }, { key: 'ecf' }], Foo);112 const viewInstance = new View(Foo, collection, (item: Foo) => item.key, foos);113 expect(viewInstance).toHaveLength(3);114 const item0a = viewInstance.list[0];115 const item2a = viewInstance.list[2];116 expect(item0a && item0a.key).toBe('abd');117 expect(item2a && item2a.key).toBe('ecf');118 const foo0 = collection.add({ key: 'ccc' }, Foo);119 expect(viewInstance).toHaveLength(3);120 viewInstance.add(foo0);121 const item0b = viewInstance.list[0];122 const item2b = viewInstance.list[2];123 expect(item0b && item0b.key).toBe('abd');124 expect(item2b && item2b.key).toBe('ccc');125 });126 it('should be able to update sort method', () => {127 class Foo extends Model {128 public static type = 'foo';129 @Attribute()130 public key!: number;131 }132 class AppCollection extends Collection {133 public static types = [Foo];134 }135 const collection = new AppCollection();136 const foos = collection.add([{ key: 2 }, { key: 3 }, { key: 1 }], Foo);137 const viewInstance = new View(Foo, collection, (item: Foo) => item.key, foos);138 expect(viewInstance).toHaveLength(3);139 const item0a = viewInstance.list[0];140 const item2a = viewInstance.list[2];141 expect(item0a && item0a.key).toBe(1);142 expect(item2a && item2a.key).toBe(3);143 let keyList: Array<number | null> = [];144 let autorunCount = 0;145 testMobx.autorun(() => {146 keyList = viewInstance.list.map((item) => item && item.key);147 autorunCount++;148 });149 expect(keyList[2]).toBe(3);150 testMobx.runInAction(() => {151 viewInstance.sortMethod = 'id';152 });153 const item0b = viewInstance.list[0];154 const item2b = viewInstance.list[2];155 expect(item0b && item0b.key).toBe(2);156 expect(item2b && item2b.key).toBe(1);157 if (mobx.useRealMobX) {158 expect(keyList[2]).toBe(1);159 expect(autorunCount).toBe(2);160 }161 });162 it('should be able to sort models by prop', () => {163 class Foo extends Model {164 public static type = 'foo';165 @Attribute()166 public key!: number;167 }168 class AppCollection extends Collection {169 public static types = [Foo];170 }171 const collection = new AppCollection();172 const foos = collection.add([{ key: 2 }, { key: 3 }, { key: 1 }], Foo);173 const viewInstance = new View(Foo, collection, 'key', foos);174 expect(viewInstance).toHaveLength(3);175 const item0a = viewInstance.list[0];176 const item2a = viewInstance.list[2];177 expect(item0a && item0a.key).toBe(1);178 expect(item2a && item2a.key).toBe(3);179 const foo0 = collection.add({ key: 0 }, Foo);180 expect(viewInstance).toHaveLength(3);181 viewInstance.add(foo0);182 const item0b = viewInstance.list[0];183 const item2b = viewInstance.list[2];184 expect(item0b && item0b.key).toBe(0);185 expect(item2b && item2b.key).toBe(2);186 });187 it('should be able to remove models', () => {188 class Foo extends Model {189 public static type = 'foo';190 }191 class AppCollection extends Collection {192 public static types = [Foo];193 }194 const collection = new AppCollection();195 const foos = collection.add([{}, {}, {}], Foo);196 const viewInstance = new View(Foo, collection, undefined, foos);197 expect(viewInstance).toHaveLength(3);198 viewInstance.remove(foos[2]);199 expect(viewInstance).toHaveLength(2);200 viewInstance.removeAll();201 expect(viewInstance).toHaveLength(0);202 });203 it('should work with updating the list', () => {204 class Foo extends Model {205 public static type = 'foo';206 }207 class AppCollection extends Collection {208 public static types = [Foo];209 }210 const collection = new AppCollection();211 const foos = collection.add([{}, {}, {}], Foo);212 const viewInstance = new View(Foo, collection, undefined, foos);213 const [foo1, foo2] = collection.add([{}, {}, {}], Foo);214 expect(viewInstance).toHaveLength(3);215 if (mobx.useRealMobX) {216 viewInstance.list.push(foo1);217 expect(viewInstance).toHaveLength(4);218 219 viewInstance.list.unshift(foo2);220 expect(viewInstance).toHaveLength(5);221 222 viewInstance.list.splice(2, 2);223 expect(viewInstance).toHaveLength(3);224 } else {225 viewInstance.list = [...viewInstance.list, foo1];226 expect(viewInstance).toHaveLength(4);227 228 viewInstance.list = [foo2, ...viewInstance.list];229 expect(viewInstance).toHaveLength(5);230 231 viewInstance.list = [...viewInstance.list.slice(0, 2), ...viewInstance.list.slice(4)];232 expect(viewInstance).toHaveLength(3);233 }234 });235 it('should work with sorted list', () => {236 class Foo extends Model {237 public static type = 'foo';238 @Attribute({ isIdentifier: true })239 public id!: number;240 }241 class AppCollection extends Collection {242 public static types = [Foo];243 }244 const collection = new AppCollection();245 const foos = collection.add([{}, {}, {}], Foo);246 const viewInstance = new View(Foo, collection, (item) => item.id, foos);247 const [foo1, foo2] = collection.add([{}, {}, {}], Foo);248 expect(viewInstance).toHaveLength(3);249 expect(() => {250 if (mobx.useRealMobX) {251 viewInstance.list.push(foo1);252 } else {253 viewInstance.list = [...viewInstance.list, foo1];254 }255 }).toThrowError(256 "New models can't be added directly to a sorted view list",257 );258 expect(() => {259 if (mobx.useRealMobX) {260 viewInstance.list.push(foo2);261 } else {262 viewInstance.list = [foo2, ...viewInstance.list];263 }264 }).toThrowError(265 "New models can't be added directly to a sorted view list",266 );267 expect(() => {268 if (mobx.useRealMobX) {269 viewInstance.list[1] = foo1;270 } else {271 viewInstance.list = [272 ...viewInstance.list.slice(0, 1),273 foo1,274 ...viewInstance.list.slice(2),275 ];276 }277 }).toThrowError("New models can't be added directly to a sorted view list");278 expect(() => {279 if (mobx.useRealMobX) {280 viewInstance.list[3] = foo1;281 } else {282 viewInstance.list = [283 ...viewInstance.list.slice(0, 3),284 foo1,285 ...viewInstance.list.slice(4),286 ];287 }288 }).toThrowError("New models can't be added directly to a sorted view list");289 if (mobx.useRealMobX) {290 viewInstance.list.splice(1, 2);291 expect(viewInstance).toHaveLength(1);292 }293 });294 it('should work with unique list', () => {295 class Foo extends Model {296 public static type = 'foo';297 @Attribute({ isIdentifier: true })298 public id!: number;299 }300 class AppCollection extends Collection {301 public static types = [Foo];302 }303 const collection = new AppCollection();304 const foos = collection.add([{}, {}, {}], Foo);305 const viewInstance = new View(Foo, collection, undefined, foos, true);306 const [foo1] = foos;307 if (mobx.useRealMobX) {308 viewInstance.list[0] = foo1;309 } else {310 viewInstance.list = [foo1, ...viewInstance.list.slice(1)];311 }312 expect(() => {313 if (mobx.useRealMobX) {314 viewInstance.list[1] = foo1;315 } else {316 viewInstance.list = [viewInstance.list[0], foo1, ...viewInstance.list.slice(2)];317 }318 }).toThrowError('The models in this view need to be unique');319 expect(() => {320 if (mobx.useRealMobX) {321 viewInstance.list.push(foo1);322 } else {323 viewInstance.list = [...viewInstance.list, foo1];324 }325 }).toThrowError(326 'The models in this view need to be unique',327 );328 expect(() => {329 if (mobx.useRealMobX) {330 viewInstance.list.splice(0, 0, foo1);331 } else {332 viewInstance.list = [foo1, ...viewInstance.list];333 }334 }).toThrowError(335 'The models in this view need to be unique',336 );337 });338 it('should be able to deserialize the view', () => {339 class Foo extends Model {340 public static type = 'foo';341 }342 class AppCollection extends Collection {343 public static types = [Foo];344 }345 const collection = new AppCollection();346 const foos = collection.add([{}, {}], Foo);347 const viewInstance = new View(Foo, collection);348 viewInstance.add(foos);349 const { snapshot } = viewInstance;350 const view2 = new View(351 snapshot.modelType,352 collection,353 undefined,354 snapshot.models,355 snapshot.unique,356 );357 expect(view2).toHaveLength(2);358 expect(view2.value[0]).toBeInstanceOf(Foo);359 expect(view2.value[1]).toBeInstanceOf(Foo);360 expect(view2.value[0]).toBe(foos[0]);361 });362 describe('Collections', () => {363 it('should be possible to add a view', () => {364 class Foo extends Model {365 public static type = 'foo';366 }367 class AppCollection extends Collection {368 public static types = [Foo];369 public test!: View<Foo>;370 }371 const collection = new AppCollection();372 const foos = collection.add([{}, {}], Foo);373 collection.addView('test', Foo, { models: foos });374 expect(collection.test).toHaveLength(2);375 expect(collection.test.value[0]).toBeInstanceOf(Foo);376 expect(collection.test.value[1]).toBeInstanceOf(Foo);377 expect(collection.test.value[0]).toBe(foos[0]);378 });379 it('should be possible to define views upfront', () => {380 class Foo extends Model {381 public static type = 'foo';382 }383 class AppCollection extends Collection {384 public static types = [Foo];385 public static views = {386 test: { modelType: Foo },387 };388 public test!: View<Foo>;389 }390 const collection = new AppCollection();391 expect(collection.test.modelType).toBe('foo');392 const foos = collection.test.add([{}, {}]);393 expect(collection.test).toHaveLength(2);394 expect(collection.test.value[0]).toBeInstanceOf(Foo);395 expect(collection.test.value[1]).toBeInstanceOf(Foo);396 expect(collection.test.value[0]).toBe(foos[0]);397 const { snapshot } = collection;398 const collection2 = new AppCollection(snapshot);399 expect(collection2.test).toHaveLength(2);400 });401 it('should be possible to define views upfront with a decorator', () => {402 class Foo extends Model {403 public static type = 'foo';404 }405 class AppCollection extends Collection {406 public static types = [Foo];407 @ViewAttribute(Foo)408 public test!: View<Foo>;409 }410 const collection = new AppCollection();411 expect(collection.test.modelType).toBe('foo');412 const foos = collection.test.add([{}, {}]);413 expect(collection.test).toHaveLength(2);414 expect(collection.test.value[0]).toBeInstanceOf(Foo);415 expect(collection.test.value[1]).toBeInstanceOf(Foo);416 expect(collection.test.value[0]).toBe(foos[0]);417 const { snapshot } = collection;418 const collection2 = new AppCollection(snapshot);419 expect(collection2.test).toHaveLength(2);420 });421 });422 it('should support changing ids', () => {423 class Foo extends Model {424 public static type = 'foo';425 }426 class AppCollection extends Collection {427 public static types = [Foo];428 }429 const collection = new AppCollection();430 const foos = collection.add([{}, {}], Foo);431 const viewInstance = new View(432 Foo,433 collection,434 undefined,435 foos.map((foo) => foo.meta.id),436 );437 expect(viewInstance).toHaveLength(2);438 expect(viewInstance.list[0]).toBeInstanceOf(Foo);439 expect(viewInstance.list[1]).toBeInstanceOf(Foo);440 expect(viewInstance.list[0]).toBe(foos[0]);441 expect(viewInstance.hasItem(foos[1])).toBe(true);442 const foo1 = foos[1];443 updateModelId(foo1, 123);444 expect(viewInstance.list[1]).toBe(foo1);445 expect(viewInstance.hasItem(foo1)).toBe(true);446 expect(foo1.meta.id).toBe(123);447 });448 it('should support ids before models', () => {449 class Foo extends Model {450 public static type = 'foo';451 @Attribute({ isIdentifier: true })452 public id!: number;453 }454 class AppCollection extends Collection {455 public static types = [Foo];456 }457 const collection = new AppCollection();458 const viewInstance = new View(Foo, collection, undefined, [987, 123, 234]);459 // const foos = collection.add([{ id: 123 }, { id: 234 }], Foo);460 const lengths: Array<number> = [];461 testMobx.autorun(() => {462 lengths.push(viewInstance.length);463 });464 testMobx.runInAction(() => {465 if (mobx.useRealMobX) {466 // @ts-expect-error467 viewInstance.list.push(876);468 } else {469 // @ts-expect-error470 viewInstance.list = [...viewInstance.list, 876];471 }472 });473 // expect(collection).toHaveLength(2);474 // expect(viewInstance).toHaveLength(2);475 // expect(viewInstance.snapshot.models).toHaveLength(4);476 // expect(viewInstance.list[0]).toBeInstanceOf(Foo);477 // expect(viewInstance.list[1]).toBeInstanceOf(Foo);478 // expect(viewInstance.list[0]).toBe(foos[0]);479 // expect(viewInstance.hasItem(foos[1])).toBe(true);480 // const foo987 = collection.add({ id: 987 }, Foo);481 // expect(collection).toHaveLength(3);482 // expect(viewInstance).toHaveLength(3);483 // expect(viewInstance.hasItem(foo987)).toBe(true);484 // // viewInstance.add({ id: 876 });485 // const foo876 = collection.add({ id: 876 }, Foo);486 // collection.add({ id: 765 }, Foo);487 // expect(collection).toHaveLength(5);488 // expect(viewInstance).toHaveLength(4);489 // expect(viewInstance.hasItem(foo876)).toBe(true);490 });...
shell.ts
Source:shell.ts
1import { inject } from 'aurelia-framework';2import { StateDirectory } from '../platform/state/state-directory';3import { StateSession } from '../platform/state/state-session';4import { ViewInstance, ViewInstanceJSON } from '../platform/state/view-instance';5@inject(StateDirectory)6export class Shell {7 public hostId: string;8 public sessionId: string;9 public session: StateSession;10 public navViewInstances = new Array<ViewInstance>();11 public navActiveViewInstance;12 public mainViewInstances = new Array<ViewInstance>();13 public mainActiveViewInstance;14 public altViewInstances = new Array<ViewInstance>();15 public altActiveViewInstance;16 constructor(private stateDirectory: StateDirectory) { }17 public launchViewInstanceJSON(viewInstanceJSON: ViewInstanceJSON) {18 let newViewInstance = ViewInstance.fromJSON(viewInstanceJSON);19 this.launchViewInstance(newViewInstance);20 this.focusViewInstance(newViewInstance);21 }22 public activate(params) {23 let that = this;24 this.hostId = params.hostId;25 this.sessionId = params.sessionId;26 this.stateDirectory.getStateSession(this.hostId, this.sessionId)27 .then(session => {28 that.session = session;29 that.session.activePaks.forEach(activePak => {30 activePak.viewInstances.forEach(viewInstance => {31 that.launchViewInstance(viewInstance);32 });33 });34 });35 }36 public focusViewInstance = (viewInstance: ViewInstance) => {37 switch (viewInstance.paneType) {38 case 'nav':39 this.navActiveViewInstance = viewInstance;40 break;41 case 'main':42 this.mainActiveViewInstance = viewInstance;43 break;44 case 'alt':45 this.altActiveViewInstance = viewInstance;46 break;47 default:48 break;49 }50 }51 public launchViewInstance = (viewInstance: ViewInstance) => {52 switch (viewInstance.paneType) {53 case 'nav':54 this.navViewInstances.push(viewInstance);55 if (!this.navActiveViewInstance) {56 this.navActiveViewInstance = viewInstance;57 }58 break;59 case 'main':60 this.mainViewInstances.push(viewInstance);61 if (!this.mainActiveViewInstance) {62 this.mainActiveViewInstance = viewInstance;63 }64 break;65 case 'alt':66 this.altViewInstances.push(viewInstance);67 if (!this.altActiveViewInstance) {68 this.altActiveViewInstance = viewInstance;69 }70 break;71 default:72 break;73 }74 }...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var viewInstance = wptoolkit.viewInstance;3var data = {4};5var view = viewInstance('test', data);6console.log(view);7This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var test = wpt('www.webpagetest.org');8test.viewTest('141219_4G_6', function(err, data) {9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var test = wpt('www.webpagetest.org');14test.getLocations(function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var test = wpt('www.webpagetest.org');20test.getTesters(function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest');25var test = wpt('www.webpagetest.org');26test.getLocations(function(err, data) {27 if (err) return console.error(err);28 console.log(data);29});30var wpt = require('webpagetest');31var test = wpt('www.webpagetest.org');32test.getTesters(function(err, data) {33 if (err) return console.error(err);34 console.log(data);35});36var wpt = require('webpagetest');37var test = wpt('www.webpagetest.org');38test.getLocations(function(err
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.viewInstance('20150916_1X_3A3', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10### new WebPageTest(serverUrl, apiKey)11### WebPageTest#runTest(url, options, callback)12Default: `{}`13### WebPageTest#getLocations(callback)14### WebPageTest#getTests(callback)15### WebPageTest#getTestResults(testId, callback)16### WebPageTest#getTestStatus(testId, callback)17### WebPageTest#getTestStatusText(testId, callback)
Using AI Code Generation
1var Wpt = require('wpt-api');2var wpt = new Wpt('API_KEY');3wpt.viewInstance(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var Wpt = require('wpt-api');11var wpt = new Wpt('API_KEY');12wpt.viewInstanceDetails(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var Wpt = require('wpt-api');20var wpt = new Wpt('API_KEY');21wpt.viewInstanceDetailsById('id', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.viewInstance(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.viewResults(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var options = {23};24wpt.viewRun(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var options = {33};34wpt.viewStatusText(options, function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!