Skip to content

Commit

Permalink
configClass (#445)
Browse files Browse the repository at this point in the history
This PR renames `CONFIG_CLASS` to `configClass` in `BaseComponent`. Even
though it's pretty much a constant, it feels more ergonomic in context
to use good ol' lowerCamelCase for it.
  • Loading branch information
danfuzz authored Dec 9, 2024
2 parents 0b220f9 + 9be53c9 commit 5451dff
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 67 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ versioning principles. Unstable releases do not.
### [Unreleased]

Breaking changes:
* None.
* `compy`:
* `BaseComponent`: Renamed `CONFIG_CLASS` to `configClass`.

Other notable changes:
* None.
Expand Down
33 changes: 16 additions & 17 deletions src/compy/export/BaseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ export class BaseComponent {
*
* **Note:** When passing `rawConfig` as a plain object, this constructor
* will attempt to construct the concrete class's defined
* {@link #CONFIG_CLASS}, and then set that as the final {@link #config}. When
* {@link #configClass}, and then set that as the final {@link #config}. When
* doing so, the constructor is passed the given `rawConfig` augmented with
* the additional binding of `class` to the concrete class being constructed
* (that is, the concrete subclass of this class whose constructor call landed
* here). See {@link BaseConfig#eval} for more details.
*
* @param {?object} [rawConfig] "Raw" (not guaranteed to be parsed and
* correct) configuration for this instance. It must either be an instance
* of the concrete class's {@link #CONFIG_CLASS}, or a plain object which is
* of the concrete class's {@link #configClass}, or a plain object which is
* acceptable to the constructor of that class, or `null` (equivalent to
* `{}`, that is, an empty object) to have no configuration properties.
* Default `null`.
Expand All @@ -74,7 +74,7 @@ export class BaseComponent {
*/
constructor(rawConfig = null, rootContext = null) {
const targetClass = new.target;
this.#config = targetClass.CONFIG_CLASS.eval(rawConfig, { targetClass });
this.#config = targetClass.configClass.eval(rawConfig, { targetClass });

const name = this.#config?.name;
if (name) {
Expand All @@ -92,7 +92,7 @@ export class BaseComponent {
/**
* @returns {?BaseConfig} Configuration object for this instance, or `null` if
* it has no associated configuration. If non-`null`, this is an instance of
* {@link #CONFIG_CLASS}.
* {@link #configClass}.
*/
get config() {
return this.#config;
Expand Down Expand Up @@ -436,20 +436,20 @@ export class BaseComponent {
//

/**
* Map from each subclass to its return value for {@link #CONFIG_CLASS},
* lazily filled in.
* Map from each subclass to its return value for {@link #configClass}, lazily
* filled in.
*
* @type {Map<function(new:BaseComponent), function(new:BaseConfig)>}
*/
static #configClass = new Map();
static #configClassMap = new Map();

/**
* @returns {function(new:BaseConfig, object)} The expected configuration
* class. for this class. Subclasses should not override this; instead they
* should override {@link #_impl_configClass}.
*/
static get CONFIG_CLASS() {
const already = BaseComponent.#configClass.get(this);
static get configClass() {
const already = BaseComponent.#configClassMap.get(this);

if (already) {
return already;
Expand All @@ -465,10 +465,10 @@ export class BaseComponent {
MustBe.subclassOf(result, BaseConfig);
} else {
const superCls = Reflect.getPrototypeOf(this);
result = superCls.CONFIG_CLASS;
result = superCls.configClass;
}

BaseComponent.#configClass.set(this, result);
BaseComponent.#configClassMap.set(this, result);
return result;
}

Expand All @@ -482,9 +482,8 @@ export class BaseComponent {
* The result array elements are derived as follows:
*
* * Instances of this class become result elements directly.
* * Plain objects and instances of this class's {@link #CONFIG_CLASS} are
* used to construct instances of this class, which then become result
* elements.
* * Plain objects and instances of this class's {@link #configClass} are used
* to construct instances of this class, which then become result elements.
* * All other values are rejected, causing an `Error` to be `throw`n.
*
* @param {*} items Single instance or configuration, or array thereof.
Expand All @@ -506,7 +505,7 @@ export class BaseComponent {
return item;
} else if (item instanceof BaseComponent) {
throw new Error('Item is not an instance of this class (or a subclass).');
} else if ((item instanceof this.CONFIG_CLASS) || AskIf.plainObject(item)) {
} else if ((item instanceof this.configClass) || AskIf.plainObject(item)) {
const { class: cls } = item;
if (AskIf.constructorFunction(cls)) {
if (AskIf.subclassOf(cls, this)) {
Expand All @@ -527,8 +526,8 @@ export class BaseComponent {

/**
* Gets the expected configuration class for this class. This (base) class
* calls this method exactly once to get the value to return from {@link
* #CONFIG_CLASS}.
* calls this method exactly once to get the value to return from
* {@link #configClass}.
*
* The default value is a configuration class which adds `name` as an optional
* configuration property, on top of (optional) `class` as defined by
Expand Down
4 changes: 2 additions & 2 deletions src/compy/export/BaseRootComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class BaseRootComponent extends BaseComponent {
// We need to recapitulate the config parsing our superclass would have done
// so that we can pass the parsed config to the `RootControlContext`
// constructor.
const config = new.target.CONFIG_CLASS.eval(rawConfig, {
const config = new.target.configClass.eval(rawConfig, {
targetClass: new.target
});

Expand All @@ -47,7 +47,7 @@ export class BaseRootComponent extends BaseComponent {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
4 changes: 2 additions & 2 deletions src/loggy-intf/private/HumanVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export class HumanVisitor extends BaseValueVisitor {
}

/**
* Styles the given text, but only if this instance has been told to be
* styled _and_ the given style function is passed as non-`null`.
* Styles the given text, but only if this instance has been told to be styled
* _and_ the given style function is passed as non-`null`.
*
* @param {string} text The text in question.
* @param {?Function} func The style/colorizer function, or `null` if no style
Expand Down
4 changes: 2 additions & 2 deletions src/net-util/export/EndpointAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { MustBe } from '@this/typey';


/**
* The address of a network endpoint, consisting of an IP address and port.
* This can be used for either the local or origin (remote) side of a network
* The address of a network endpoint, consisting of an IP address and port. This
* can be used for either the local or origin (remote) side of a network
* connection. This class only accepts numerical IP addresses, not hostnames.
* Instances of this class are immutable.
*
Expand Down
12 changes: 6 additions & 6 deletions src/net-util/export/InterfaceAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class InterfaceAddress extends IntfDeconstructable {
*
* @param {string|object} fullAddress The full address, in one of the forms
* mentioned above.
* @param {?object} nodeServerOptions Extra options to use when constructing
* a Node {@link Server} object or calling `listen()` on one; or `null` not
* to have extra options beyond the defaults.
* @param {?object} nodeServerOptions Extra options to use when constructing a
* Node {@link Server} object or calling `listen()` on one; or `null` not to
* have extra options beyond the defaults.
*/
constructor(fullAddress, nodeServerOptions = null) {
super();
Expand Down Expand Up @@ -224,9 +224,9 @@ export class InterfaceAddress extends IntfDeconstructable {
}

/**
* Indicates whether or not this instance represents the same interface as
* the given object. This only returns `true` if `other` is also an instance
* of this class.
* Indicates whether or not this instance represents the same interface as the
* given object. This only returns `true` if `other` is also an instance of
* this class.
*
* @param {*} other Object to compare to.
* @returns {boolean} `true` if `this` and `other` represent the same
Expand Down
6 changes: 3 additions & 3 deletions src/valvis/export/BaseValueVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ export class BaseValueVisitor {
/**
* Similar to {@link #visitWrap}, except (a) it will fail if the visit did not
* finish synchronously; and (b) the result is not wrapped. Specifically with
* respect to (b), if a promise is returned, it is only ever
* because an `_impl_visit*()` method returned a promise result per se (and
* not because a visitor acted asynchronously).
* respect to (b), if a promise is returned, it is only ever because an
* `_impl_visit*()` method returned a promise result per se (and not because a
* visitor acted asynchronously).
*
* @returns {*} Whatever result was returned from the `_impl_*()` method which
* processed the original `value`.
Expand Down
6 changes: 3 additions & 3 deletions src/valvis/export/VisitDef.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { VisitRef } from '#x/VisitRef';


/**
* Representation of a result of a (sub-)visit which appears more than
* once in an overall visit result.
* Representation of a result of a (sub-)visit which appears more than once in
* an overall visit result.
*/
export class VisitDef extends BaseDefRef {
/**
Expand All @@ -21,7 +21,7 @@ export class VisitDef extends BaseDefRef {

/**
* The error resulting from the visit, or `null` if there was none _or_ it is
* not yet known.
* not yet known.
*
* @type {?Error}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/AccessLogToFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class AccessLogToFile extends BaseFileService {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/ConnectionRateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ConnectionRateLimiter extends BaseService {
static _impl_configClass() {
return TemplRateLimitConfig(
'ConnectionRateLimiterConfig',
BaseService.CONFIG_CLASS,
BaseService.configClass,
{
countType: ConnectionCount,
rateType: ConnectionRate
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/DataRateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class DataRateLimiter extends BaseService {
static _impl_configClass() {
const baseClass = TemplRateLimitConfig(
'DataRateJustLimiterConfig',
BaseService.CONFIG_CLASS,
BaseService.configClass,
{
allowMaxQueueGrant: true,
countType: ByteCount,
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/EventFan.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class EventFan extends BaseService {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/HostRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class HostRouter extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
/**
* Map which goes from a host prefix to the name of an application which
* should handle that prefix. Each host must be a valid
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/MemoryMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class MemoryMonitor extends TemplThreadComponent('MemoryThread', BaseServ

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/PathRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class PathRouter extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/ProcessIdFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class ProcessIdFile extends TemplThreadComponent('FileThread', BaseFileSe

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/ProcessInfoFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class ProcessInfoFile extends TemplThreadComponent('FileThread', BaseFile

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/Redirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Redirector extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/RequestDelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class RequestDelay extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/RequestFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class RequestFilter extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/RequestRateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class RequestRateLimiter extends BaseApplication {
static _impl_configClass() {
return TemplRateLimitConfig(
'RequestRateLimiterConfig',
BaseApplication.CONFIG_CLASS,
BaseApplication.configClass,
{
countType: RequestCount,
rateType: RequestRate
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/SerialRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class SerialRouter extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/SimpleResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class SimpleResponse extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/StaticFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class StaticFiles extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/SuffixRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class SuffixRouter extends BaseApplication {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-builtins/export/SyslogToFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class SyslogToFile extends BaseFileService {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-core/export/BaseDispatched.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class BaseDispatched extends BaseComponent {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
2 changes: 1 addition & 1 deletion src/webapp-core/export/NetworkEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class NetworkEndpoint extends BaseDispatched {

/** @override */
static _impl_configClass() {
return class Config extends super.prototype.constructor.CONFIG_CLASS {
return class Config extends super.prototype.constructor.configClass {
// @defaultConstructor

/**
Expand Down
Loading

0 comments on commit 5451dff

Please sign in to comment.