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) {
return types_PRIVATE.get(type);
return _types.get(type);
}
export function register(type, info) {
@ -22,5 +22,5 @@ export function register(type, info) {
identity: (value, step) => { return value },
...info.valueMap,
}
types_PRIVATE.set(type, info);
_types.set(type, info);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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