chore: _PRIVATE removed

This commit is contained in:
cha0s 2019-04-07 13:00:11 -04:00
parent 7de34a7669
commit 71a215c8a6
9 changed files with 104 additions and 103 deletions

View File

@ -1,7 +1,7 @@
const types_PRIVATE = new Map(); const _types = new Map();
export function get(type) { export function get(type) {
return types_PRIVATE.get(type); return _types.get(type);
} }
export function register(type, info) { export function register(type, info) {
@ -22,5 +22,5 @@ export function register(type, info) {
identity: (value, step) => { return value }, identity: (value, step) => { return value },
...info.valueMap, ...info.valueMap,
} }
types_PRIVATE.set(type, info); _types.set(type, info);
} }

View File

@ -13,17 +13,17 @@ export class Actions extends Traversals {
constructor() { constructor() {
super(); super();
this.index_PRIVATE = 0; this._index = 0;
this.traversals = []; this.traversals = [];
this.pending = null; this.pending = null;
} }
get index() { get index() {
return this.index_PRIVATE; return this._index;
} }
set index(index) { set index(index) {
this.index_PRIVATE = index; this._index = index;
} }
tick(context, elapsed) { tick(context, elapsed) {

View File

@ -13,7 +13,7 @@ class TraitProxy {
return Reflect.has(entity, property, receiver); return Reflect.has(entity, property, receiver);
} }
else { else {
return entity.traits_PRIVATE.hasProperty(property); return entity._traits.hasProperty(property);
} }
} }
@ -22,7 +22,7 @@ class TraitProxy {
return Reflect.get(entity, property, receiver); return Reflect.get(entity, property, receiver);
} }
else { else {
return entity.traits_PRIVATE.getProperty(property); return entity._traits.getProperty(property);
} }
} }
@ -31,7 +31,7 @@ class TraitProxy {
return Reflect.set(entity, property, value, receiver); return Reflect.set(entity, property, value, receiver);
} }
else { else {
if (!entity.traits_PRIVATE.setProperty(property, value, receiver)) { if (!entity._traits.setProperty(property, value, receiver)) {
return Reflect.set(entity, property, value, receiver); return Reflect.set(entity, property, value, receiver);
} }
else { else {
@ -50,61 +50,61 @@ class Entity extends decorate(Resource) {
constructor() { constructor() {
super(); super();
this.isTicking_PRIVATE = true; this._isTicking = true;
this.traits_PRIVATE = new Traits(createProxy(this)); this._traits = new Traits(createProxy(this));
} }
addTrait(type, trait) { addTrait(type, trait) {
this.traits_PRIVATE.addTrait(type, trait); this._traits.addTrait(type, trait);
} }
addTraits(traits) { addTraits(traits) {
for (const type in traits) { for (const type in traits) {
this.traits_PRIVATE.addTrait(type, traits[type]); this._traits.addTrait(type, traits[type]);
} }
} }
allTraitInstances() { allTraitInstances() {
return this.traits_PRIVATE.allInstances(); return this._traits.allInstances();
} }
allTraitTypes() { allTraitTypes() {
return this.traits_PRIVATE.allTypes(); return this._traits.allTypes();
} }
fromJSON(json) { fromJSON(json) {
super.fromJSON(json); super.fromJSON(json);
this.traits_PRIVATE.fromJSON(json.traits); this._traits.fromJSON(json.traits);
return this; return this;
} }
is(type) { is(type) {
return this.traits_PRIVATE.hasTrait(type); return this._traits.hasTrait(type);
} }
hydrate() { hydrate() {
return this.traits_PRIVATE.hydrate(); return this._traits.hydrate();
} }
invokeHook(hook, ...args) { invokeHook(hook, ...args) {
return this.traits_PRIVATE.invokeHook(hook, ...args); return this._traits.invokeHook(hook, ...args);
} }
invokeHookFlat(hook, ...args) { invokeHookFlat(hook, ...args) {
return this.traits_PRIVATE.invokeHookFlat(hook, ...args); return this._traits.invokeHookFlat(hook, ...args);
} }
patchState(patch) { patchState(patch) {
this.traits_PRIVATE.patchState(patch); this._traits.patchState(patch);
} }
removeAllTraits() { removeAllTraits() {
const types = this.traits_PRIVATE.allTypes(); const types = this._traits.allTypes();
this.removeTraits(types); this.removeTraits(types);
} }
removeTrait(type) { removeTrait(type) {
this.traits_PRIVATE.removeTrait(type); this._traits.removeTrait(type);
} }
removeTraits(types) { removeTraits(types) {
@ -112,13 +112,13 @@ class Entity extends decorate(Resource) {
} }
get state() { get state() {
return this.traits_PRIVATE.state; return this._traits.state;
} }
toJSON() { toJSON() {
return { return {
...super.toJSON(), ...super.toJSON(),
traits: this.traits_PRIVATE.toJSON(), traits: this._traits.toJSON(),
} }
} }

View File

@ -16,21 +16,21 @@ export class EntityList extends decorate(Synchronized) {
constructor() { constructor() {
super(); super();
this.entities_PRIVATE = {}; this._entities = {};
this._quadTree = new QuadTree(); this._quadTree = new QuadTree();
this.uuidMap_PRIVATE = {}; this._uuidMap = {};
} }
*[Symbol.iterator]() { *[Symbol.iterator]() {
for (const uuid in this.entities_PRIVATE) { for (const uuid in this._entities) {
const entity = this.entities_PRIVATE[uuid]; const entity = this._entities[uuid];
yield entity; yield entity;
} }
} }
addEntity(entity) { addEntity(entity) {
const uuid = entity.instanceUuid; const uuid = entity.instanceUuid;
this.entities_PRIVATE[uuid] = entity; this._entities[uuid] = entity;
this.state = this.state.set(uuid, entity.state); this.state = this.state.set(uuid, entity.state);
entity.addTrait('listed'); entity.addTrait('listed');
entity.list = this; entity.list = this;
@ -47,17 +47,17 @@ export class EntityList extends decorate(Synchronized) {
} }
findEntity(uuid) { findEntity(uuid) {
if (this.uuidMap_PRIVATE[uuid]) { if (this._uuidMap[uuid]) {
return this.entities_PRIVATE[this.uuidMap_PRIVATE[uuid]]; return this._entities[this._uuidMap[uuid]];
} }
if (this.entities_PRIVATE[uuid]) { if (this._entities[uuid]) {
return this.entities_PRIVATE[uuid]; return this._entities[uuid];
} }
} }
patchStateStep(uuid, step) { patchStateStep(uuid, step) {
const localUuid = this.uuidMap_PRIVATE[uuid]; const localUuid = this._uuidMap[uuid];
const entity = this.entities_PRIVATE[localUuid]; const entity = this._entities[localUuid];
if (entity) { if (entity) {
if (false === step.value) { if (false === step.value) {
// Entity removed. // Entity removed.
@ -74,7 +74,7 @@ export class EntityList extends decorate(Synchronized) {
const newEntity = create().fromJSON({ const newEntity = create().fromJSON({
traits: step.value, traits: step.value,
}); });
this.uuidMap_PRIVATE[uuid] = newEntity.instanceUuid; this._uuidMap[uuid] = newEntity.instanceUuid;
this.addEntity(newEntity); this.addEntity(newEntity);
} }
} }
@ -85,7 +85,7 @@ export class EntityList extends decorate(Synchronized) {
removeEntity(entity) { removeEntity(entity) {
const uuid = entity.instanceUuid; const uuid = entity.instanceUuid;
delete this.entities_PRIVATE[uuid]; delete this._entities[uuid];
this.state = this.state.delete(uuid); this.state = this.state.delete(uuid);
this.emit('entityRemoved', entity); this.emit('entityRemoved', entity);
if (entity.is('listed')) { if (entity.is('listed')) {
@ -94,8 +94,8 @@ export class EntityList extends decorate(Synchronized) {
} }
tick(elapsed) { tick(elapsed) {
for (const uuid in this.entities_PRIVATE) { for (const uuid in this._entities) {
const entity = this.entities_PRIVATE[uuid]; const entity = this._entities[uuid];
if ('tick' in entity) { if ('tick' in entity) {
entity.tick(elapsed); entity.tick(elapsed);
this.state = this.state.set(uuid, entity.state); this.state = this.state.set(uuid, entity.state);

View File

@ -29,22 +29,22 @@ export class Traits extends Synchronized {
constructor(entity) { constructor(entity) {
super(); super();
this.methods_PRIVATE = {}; this._methods = {};
this.entity_PRIVATE = entity; this._entity = entity;
this.hooks_PRIVATE = {}; this._hooks = {};
this.properties_PRIVATE = {}; this._properties = {};
this.traits_PRIVATE = {}; this._traits = {};
entity.once('destroyed', () => { entity.once('destroyed', () => {
this.removeAllTraits(); this.removeAllTraits();
}); });
} }
allInstances() { allInstances() {
return this.traits_PRIVATE; return this._traits;
} }
allTypes() { allTypes() {
return Object.keys(this.traits_PRIVATE); return Object.keys(this._traits);
} }
addTrait(type, json = {}) { addTrait(type, json = {}) {
@ -71,19 +71,19 @@ export class Traits extends Synchronized {
} }
// Instantiate. // Instantiate.
const {params, state} = json; const {params, state} = json;
const instance = new Trait(this.entity_PRIVATE, params, state); const instance = new Trait(this._entity, params, state);
// Proxy properties. // Proxy properties.
const properties = enumerateProperties(Trait.prototype); const properties = enumerateProperties(Trait.prototype);
for (const key in properties) { for (const key in properties) {
properties[key].instance = instance; properties[key].instance = instance;
this.properties_PRIVATE[key] = properties[key]; this._properties[key] = properties[key];
} }
// Let the Trait do its initialization. // Let the Trait do its initialization.
instance.initialize(); instance.initialize();
// Attach listeners. // Attach listeners.
const listeners = instance.listeners(); const listeners = instance.listeners();
for (const eventName in listeners) { for (const eventName in listeners) {
this.entity_PRIVATE.on( this._entity.on(
`${eventName}.trait-${type}`, `${eventName}.trait-${type}`,
listeners[eventName] listeners[eventName]
); );
@ -91,13 +91,13 @@ export class Traits extends Synchronized {
// Proxy methods. // Proxy methods.
const methods = instance.methods(); const methods = instance.methods();
for (const key in methods) { for (const key in methods) {
this.methods_PRIVATE[key] = methods[key]; this._methods[key] = methods[key];
} }
// Register hook listeners. // Register hook listeners.
const hooks = instance.hooks(); const hooks = instance.hooks();
for (const key in hooks) { for (const key in hooks) {
this.hooks_PRIVATE[key] = this.hooks_PRIVATE[key] || []; this._hooks[key] = this._hooks[key] || [];
this.hooks_PRIVATE[key].push({ this._hooks[key].push({
fn: hooks[key], fn: hooks[key],
type: Trait.type(), type: Trait.type(),
}); });
@ -105,8 +105,8 @@ export class Traits extends Synchronized {
// Add state. // Add state.
this._setInstanceState(type, instance); this._setInstanceState(type, instance);
// Track trait. // Track trait.
this.traits_PRIVATE[type] = instance; this._traits[type] = instance;
this.entity_PRIVATE.emit('traitAdded', type, instance); this._entity.emit('traitAdded', type, instance);
} }
addTraits(traits) { addTraits(traits) {
@ -122,12 +122,12 @@ export class Traits extends Synchronized {
} }
getProperty(property) { getProperty(property) {
if (property in this.methods_PRIVATE) { if (property in this._methods) {
return this.methods_PRIVATE[property]; return this._methods[property];
} }
if (property in this.properties_PRIVATE) { if (property in this._properties) {
const instance = this.properties_PRIVATE[property].instance; const instance = this._properties[property].instance;
if (!this.properties_PRIVATE[property].get) { if (!this._properties[property].get) {
const type = instance.constructor.type(); const type = instance.constructor.type();
throw new ReferenceError( throw new ReferenceError(
`Property '${property}' from Trait '${type}' has no getter` `Property '${property}' from Trait '${type}' has no getter`
@ -138,38 +138,38 @@ export class Traits extends Synchronized {
} }
hasProperty(property) { hasProperty(property) {
if (property in this.methods_PRIVATE) { if (property in this._methods) {
return true; return true;
} }
if (property in this.properties_PRIVATE) { if (property in this._properties) {
return true; return true;
} }
return false; return false;
} }
hasTrait(type) { hasTrait(type) {
return type in this.traits_PRIVATE; return type in this._traits;
} }
hydrate() { hydrate() {
const promises = []; const promises = [];
for (const type in this.traits_PRIVATE) { for (const type in this._traits) {
const instance = this.traits_PRIVATE[type]; const instance = this._traits[type];
promises.push(instance.hydrate()); promises.push(instance.hydrate());
} }
return Promise.all(promises); return Promise.all(promises);
} }
instance(type) { instance(type) {
return this.traits_PRIVATE[type]; return this._traits[type];
} }
invokeHook(hook, ...args) { invokeHook(hook, ...args) {
const results = {}; const results = {};
if (!(hook in this.hooks_PRIVATE)) { if (!(hook in this._hooks)) {
return results; return results;
} }
for (const {fn, type} of this.hooks_PRIVATE[hook]) { for (const {fn, type} of this._hooks[hook]) {
results[type] = fn(...args); results[type] = fn(...args);
} }
return results; return results;
@ -185,15 +185,15 @@ export class Traits extends Synchronized {
} }
patchStateStep(type, step) { patchStateStep(type, step) {
let instance = this.traits_PRIVATE[type]; let instance = this._traits[type];
// New trait requested? // New trait requested?
if (!this.traits_PRIVATE[type]) { if (!this._traits[type]) {
// Doesn't exist? // Doesn't exist?
if (!hasTrait(type)) { if (!hasTrait(type)) {
return; return;
} }
this.addTrait(type, step.value); this.addTrait(type, step.value);
instance = this.traits_PRIVATE[type]; instance = this._traits[type];
} }
else { else {
// Accept state. // Accept state.
@ -213,29 +213,29 @@ export class Traits extends Synchronized {
return; return;
} }
const instance = this.traits_PRIVATE[type]; const instance = this._traits[type];
instance.destroy(); instance.destroy();
const methods = instance.methods(); const methods = instance.methods();
for (const key in methods) { for (const key in methods) {
delete this.methods_PRIVATE[key]; delete this._methods[key];
} }
const hooks = instance.hooks(); const hooks = instance.hooks();
for (const key in hooks) { for (const key in hooks) {
delete this.hooks_PRIVATE[key]; delete this._hooks[key];
} }
const Trait = lookupTrait(type); const Trait = lookupTrait(type);
const properties = enumerateProperties(Trait.prototype); const properties = enumerateProperties(Trait.prototype);
for (const key in properties) { for (const key in properties) {
delete this.properties_PRIVATE[key]; delete this._properties[key];
} }
this.entity_PRIVATE.off(`.trait-${type}`); this._entity.off(`.trait-${type}`);
this.state = this.state.delete(type); this.state = this.state.delete(type);
delete this.traits_PRIVATE[type]; delete this._traits[type];
} }
removeTraits(types) { removeTraits(types) {
@ -251,10 +251,10 @@ export class Traits extends Synchronized {
} }
setProperty(property, value, receiver) { setProperty(property, value, receiver) {
if (property in this.properties_PRIVATE) { if (property in this._properties) {
const instance = this.properties_PRIVATE[property].instance; const instance = this._properties[property].instance;
const type = instance.constructor.type(); const type = instance.constructor.type();
if (!this.properties_PRIVATE[property].set) { if (!this._properties[property].set) {
throw new ReferenceError( throw new ReferenceError(
`Property '${property}' from Trait '${type}' has no setter` `Property '${property}' from Trait '${type}' has no setter`
); );
@ -268,8 +268,8 @@ export class Traits extends Synchronized {
toJSON() { toJSON() {
const json = {}; const json = {};
for (const type in this.traits_PRIVATE) { for (const type in this._traits) {
json[type] = this.traits_PRIVATE[type].toJSON(); json[type] = this._traits[type].toJSON();
} }
return json; return json;
} }

View File

@ -163,18 +163,18 @@ export function EventEmitterMixin(Superclass) {
} }
on(types, fn, that = undefined) { on(types, fn, that = undefined) {
this.on_PRIVATE(types, fn, that, false); this._on(types, fn, that, false);
return this; return this;
} }
on_PRIVATE(typesOrType, fn, that, once) { _on(typesOrType, fn, that, once) {
parseTypes(typesOrType).forEach((typeOrCompositeType) => { parseTypes(typesOrType).forEach((typeOrCompositeType) => {
this.onSingleEvent(typeOrCompositeType, fn, that, once); this.onSingleEvent(typeOrCompositeType, fn, that, once);
}); });
} }
once(types, fn, that = undefined) { once(types, fn, that = undefined) {
this.on_PRIVATE(types, fn, that, true); this._on(types, fn, that, true);
return this; return this;
} }

View File

@ -16,7 +16,7 @@ class TransitionResult {
// milliseconds. // milliseconds.
this.duration = parseInt(duration || 100); this.duration = parseInt(duration || 100);
this.elapsed = 0; this.elapsed = 0;
this.isEmittingProgress_PRIVATE = false; this._isEmittingProgress = false;
this.props = props; this.props = props;
this.subject = subject; this.subject = subject;
@ -45,11 +45,11 @@ class TransitionResult {
} }
get isEmittingProgress() { get isEmittingProgress() {
return this.isEmittingProgress_PRIVATE; return this._isEmittingProgress;
} }
set isEmittingProgress(isEmittingProgress) { set isEmittingProgress(isEmittingProgress) {
this.isEmittingProgress_PRIVATE = isEmittingProgress; this._isEmittingProgress = isEmittingProgress;
} }
// Immediately finish the transition. This will leave the object // Immediately finish the transition. This will leave the object
@ -67,7 +67,7 @@ class TransitionResult {
stopTransition() { stopTransition() {
// Let any listeners know that the transition is complete. // Let any listeners know that the transition is complete.
if (this.isEmittingProgress_PRIVATE) { if (this._isEmittingProgress) {
this.emit('progress', [this.elapsed, this.duration]); this.emit('progress', [this.elapsed, this.duration]);
} }
this.emit('stopped'); this.emit('stopped');
@ -110,7 +110,7 @@ class TransitionResult {
this.stopTransition(); this.stopTransition();
} }
else { else {
if (this.isEmittingProgress_PRIVATE) { if (this._isEmittingProgress) {
this.emit('progress', [this.elapsed, this.duration]); this.emit('progress', [this.elapsed, this.duration]);
} }
} }

View File

@ -39,45 +39,45 @@ export class Resource {
} }
constructor() { constructor() {
this.uri_PRIVATE = undefined; this._uri = undefined;
this.uuid_PRIVATE = undefined; this._uuid = undefined;
this.instanceUuid_PRIVATE = uuid(); this._instanceUuid = uuid();
} }
fromJSON({uri, uuid}) { fromJSON({uri, uuid}) {
this.uri_PRIVATE = uri; this._uri = uri;
this.uuid_PRIVATE = uuid; this._uuid = uuid;
return this; return this;
} }
get instanceUuid() { get instanceUuid() {
return this.instanceUuid_PRIVATE; return this._instanceUuid;
} }
regenerateUuid() { regenerateUuid() {
this.uuid_PRIVATE = uuid(); this._uuid = uuid();
} }
get uuid() { get uuid() {
return this.uuid_PRIVATE; return this._uuid;
} }
set uuid(uuid) { set uuid(uuid) {
this.uuid_PRIVATE = uuid; this._uuid = uuid;
} }
get uri() { get uri() {
return this.uri_PRIVATE; return this._uri;
} }
set uri(uri) { set uri(uri) {
this.uri_PRIVATE = uri; this._uri = uri;
} }
toJSON() { toJSON() {
return { return {
uuid: this.uuid_PRIVATE, uuid: this._uuid,
uri: this.uri_PRIVATE, uri: this._uri,
}; };
} }

View File

@ -17,6 +17,7 @@ export class Tiles extends decorate(Synchronized) {
constructor() { constructor() {
super(); super();
this.data = I.List(); this.data = I.List();
console.log(this);
} }
patchStateStep(key, step) { patchStateStep(key, step) {