UNPKG

@theoplayer/react-native-engage

Version:
43 lines (42 loc) 1.21 kB
"use strict"; import { AddOperation, ClusterEntitiesChangedEvent } from "@theoplayer/react-native-engage"; import { Cluster } from "../../api/cluster/Cluster"; export class DefaultCluster extends Cluster { constructor(engageClient, type, entities = []) { super(); this.engageClient = engageClient; this.type = type; this.entities = entities; } get config() { return this.clusterConfig; } set config(config) { this.clusterConfig = config; this.update(); } update() { this.engageClient.publish(this); this.dispatchEvent(new ClusterEntitiesChangedEvent()); } addEntity(entity, op = AddOperation.AddToFront) { switch (op) { case AddOperation.AddToBack: this.entities = [...this.entities.filter(e => e.id !== entity.id), entity]; break; case AddOperation.AddToFront: this.entities = [entity, ...this.entities.filter(e => e.id !== entity.id)]; break; } this.update(); } removeEntity(entity) { this.entities = this.entities.filter(e => e.id !== entity.id); this.update(); } removeAllEntities() { this.entities = []; this.update(); } } //# sourceMappingURL=DefaultCluster.js.map