Skip to content

Commit

Permalink
docs(agents): Add remaining docs for prototype registry refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Aug 26, 2019
1 parent 29a7684 commit 29a0024
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/agents/impl/prototype/prototype-registry-impl-base.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
/*
* Contains the abstract base class for `PrototypeRegistry` implementations,
* which implements the shared functionality between the static and non-static
* prototype registries.
*
* Copyright (c) Joseph R Cowman
* Licensed under MIT License (see https://github.com/regal/regal)
*/

import { PKProvider } from "../../../common";
import { RegalError } from "../../../error";
import { Agent } from "../../agent";
import { AgentProtoId } from "../../agent-meta";
import { PrototypeRegistry } from "../../prototype-registry";
import { getInstanceStateAgentProtoPK } from "./agent-proto-keys";

/**
* Helper interface for the structure of `PrototypeRegistryImplBase`'s
* internal prototype store.
*/
export interface ProtoRegistryStore {
[key: string]: object;
}

/**
* Abstract base class for `PrototypeRegistry`.
*/
export abstract class PrototypeRegistryImplBase implements PrototypeRegistry {
constructor(protected _store: ProtoRegistryStore = {}) {}

Expand Down Expand Up @@ -60,5 +76,8 @@ export abstract class PrototypeRegistryImplBase implements PrototypeRegistry {

public abstract copy(): PrototypeRegistry;

/**
* Returns the prototype registry's `AgentProtoId` `PKProvider`.
*/
protected abstract getProtoPKProvider(): PKProvider<AgentProtoId>;
}
10 changes: 10 additions & 0 deletions src/agents/impl/prototype/prototype-registry-impl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Contains the non-static `PrototypeRegistry` implementation.
*
* Copyright (c) Joseph R Cowman
* Licensed under MIT License (see https://github.com/regal/regal)
*/

import { PKProvider } from "../../../common";
import { AgentProtoId } from "../../agent-meta";
import { PrototypeRegistry } from "../../prototype-registry";
Expand All @@ -13,6 +20,9 @@ export const buildPrototypeRegistry = (
pkProvider: PKProvider<AgentProtoId>
): PrototypeRegistry => new PrototypeRegistryImpl(pkProvider);

/**
* Non-static `PrototypeRegistry` implementation.
*/
class PrototypeRegistryImpl extends PrototypeRegistryImplBase {
constructor(
private _pkProvider: PKProvider<AgentProtoId>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Contains the static `PrototypeRegistry` type definition and implementation.
* Contains the `StaticPrototypeRegistry` type definition and implementation.
*
* Copyright (c) Joseph R Cowman
* Licensed under MIT License (see https://github.com/regal/regal)
Expand Down
11 changes: 11 additions & 0 deletions src/agents/prototype-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ export interface PrototypeRegistry {
*/
newInstance(prototypeId: AgentProtoId): Agent;

/**
* Creates an agent from the registered prototype specified by the given id,
* using `Object.create()`. Returns `undefined` if no prototype exists with the id.
* @param prototypeId The prototype id.
*/
newInstanceOrDefault(prototypeId: AgentProtoId): Agent;

/**
* Gets the `protoId` which corresponds to the given prototype, or returns undefined
* if none exists.
* @param obj The `Agent` prototype.
*/
getPrototypeIdOrDefault(obj: Agent): AgentProtoId;

/** Makes a deep copy of this `PrototypeRegistry`. */
copy(): PrototypeRegistry;
}

Expand Down

0 comments on commit 29a0024

Please sign in to comment.