feat: events for add/remove entity in list

This commit is contained in:
cha0s 2019-03-18 19:58:22 -05:00
parent c240ee6337
commit 101b443316

View File

@ -1,9 +1,16 @@
import * as I from 'immutable';
import mapValues from 'lodash.mapvalues';
import {compose} from '@avocado/core';
import {EventEmitter} from '@avocado/mixins';
import {create} from './index';
export class EntityList {
const decorate = compose(
EventEmitter,
);
class EntityListBase {
constructor() {
this.entities_PRIVATE = {};
@ -51,6 +58,7 @@ export class EntityList {
entity.on('destroyed', () => {
this.removeEntity(entity);
});
this.emit('entityAdded', entity);
}
entity(uuid) {
@ -68,6 +76,7 @@ export class EntityList {
const uuid = entity.instanceUuid;
delete this.entities_PRIVATE[uuid];
this.state_PRIVATE = this.state_PRIVATE.delete(uuid);
this.emit('entityRemoved', entity);
}
state() {
@ -85,3 +94,5 @@ export class EntityList {
}
}
export class EntityList extends decorate(EntityListBase) {}