diff options
Diffstat (limited to 'src/data/thing.js')
-rw-r--r-- | src/data/thing.js | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/data/thing.js b/src/data/thing.js index 706e893d..29f50d23 100644 --- a/src/data/thing.js +++ b/src/data/thing.js @@ -17,17 +17,52 @@ export default class Thing extends CacheableObject { static yamlDocumentSpec = Symbol.for('Thing.yamlDocumentSpec'); static getYamlLoadingSpec = Symbol.for('Thing.getYamlLoadingSpec'); + static isThingConstructor = Symbol.for('Thing.isThingConstructor'); + static isThing = Symbol.for('Thing.isThing'); + + // To detect: + // Symbol.for('Thing.isThingConstructor') in constructor + static [Symbol.for('Thing.isThingConstructor')] = NaN; + + static [CacheableObject.propertyDescriptors] = { + // To detect: + // Object.hasOwn(object, Symbol.for('Thing.isThing')) + [Symbol.for('Thing.isThing')]: { + flags: {expose: true}, + expose: {compute: () => NaN}, + }, + }; + + static [Symbol.for('Thing.selectAll')] = _wikiData => []; + // Default custom inspect function, which may be overridden by Thing // subclasses. This will be used when displaying aggregate errors and other // command-line logging - it's the place to provide information useful in // identifying the Thing being presented. [inspect.custom]() { - const cname = this.constructor.name; + const constructorName = this.constructor.name; + + let name; + try { + if (this.name) { + name = colors.green(`"${this.name}"`); + } + } catch (error) { + name = colors.yellow(`couldn't get name`); + } + + let reference; + try { + if (this.directory) { + reference = colors.blue(Thing.getReference(this)); + } + } catch (error) { + reference = colors.yellow(`couldn't get reference`); + } return ( - (this.name ? `${cname} ${colors.green(`"${this.name}"`)}` : `${cname}`) + - (this.directory ? ` (${colors.blue(Thing.getReference(this))})` : '') - ); + (name ? `${constructorName} ${name}` : `${constructorName}`) + + (reference ? ` (${reference})` : '')); } static getReference(thing) { |