feat: events for add/remove entity in list
This commit is contained in:
parent
c240ee6337
commit
101b443316
|
@ -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) {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user