Command Palette

Search for a command to run...

Назад к скиллам
скилл № 29067

hoc-classes-inflators

Convention for class inflator methods (binding methods): static methods that bind a value to a class and return a derived subclass. Use when writing, naming…

БесплатноБез исполняемых скриптов
openreachtechот openreachtech★ 17 звёзд на GitHub

Установить hoc-classes-inflators в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Classes: Inflators

This summarizes conventions related to inflator methods (binding methods).

What is an inflator method

  • An inflator method is a static method that binds the class passed as an argument (= binding) and returns a memoized derived subclass.
  • The returned derived subclass is one where the base class's abstract member has been overridden to return the binding.
  • "The same combination of bindings returns the same derived class" (memoization) is the core of this pattern.
  • The implementation is delegated to BoundCtorRegistry (lib/tools/BoundCtorRegistry.js). Do not cache derived classes yourself.
export default class UnionScalar extends BaseScalar {
  // Inflator method: binds the passed schemas and returns a memoized derived subclass
  static of (...schemas) {
    const registry = BoundCtorRegistry.create({
      BaseCtor: this,
    })

    return registry.ensureBoundCtor({
      bindings: schemas,
      deriver: ({ Ctor }) => class extends Ctor {
        /** @override */
        static get boundSchemas () {
          return schemas
        }
      },
    })
  }

  // from delegates to of
  static from (schemas) {
    return this.of(...schemas)
  }

  // abstract member overridden by the inflator
  /** @abstract */
  static get boundSchemas () {
    throw new Error(`${this.name}.get:boundSchemas must be inherited`)
  }
}

Define the inflator as a static method on the target class being bound itself

  • An inflator method should be defined as a static method on the target class being bound itself, not as an external utility.
  • Unless there is a specific reason otherwise, pass this as BaseCtor in BoundCtorRegistry.create({ BaseCtor }), so that an inflator called from a subclass derives from that subclass. Why a static member refers to its own class through this belongs to /hoc-scope.
// NG: hardcoding the class name in BaseCtor
static of (...schemas) {
  const registry = BoundCtorRegistry.create({
    BaseCtor: UnionScalar, // ❌️ anchors to UnionScalar even when called from a subclass
  })
  // ...
}

// OK: this for BaseCtor
static of (...schemas) {
  const registry = BoundCtorRegistry.create({
    BaseCtor: this,
  })
  // ...
}
  • Exception: the graft family described later (.onto() / .into()) intentionally puts BaseCtor on the argument side (the direction is reversed).

Values bound must be objects

  • The value (binding) passed to and bound by an inflator must be an object. Primitives (strings, numbers, booleans, etc.) cannot be bound.
  • Reason: BoundCtorRegistry uses the binding as a WeakMap key for memoization. WeakMap keys are restricted to objects (and Symbols).
  • What is actually bound is typically a class (constructor = a function object), a schema object, or a config object, so this constraint is naturally satisfied.

Memoization semantics

  • The granularity of memoization is the combination of bindings (i.e. reference identity of the objects). The same binding returns the same derived class.
UnionScalar.of(A, B) === UnionScalar.of(A, B) // true (same binding → same class)
UnionScalar.of(A, B) === UnionScalar.of(A, C) // false (different binding → different class)
  • The derived class inherits from the base and retains the base class's name (BoundCtorRegistry names it with { [BaseCtor.name]: class extends ... {} }).
const Bound = OriginalCtor.use(FirstConstraint)

Bound.prototype instanceof OriginalCtor // true
Bound.name // 'OriginalCtor'
  • Since inflators are memoized, they are safe to call every time. There's no need for the caller to store the inflator's return value in a variable to cache it.
// OK: it is fine to inflate on every call (memoization prevents wasteful creation)
inflateMessageCtor () {
  return this.MessageCtor
    .use(this.MessageDeserializerCtor)
    .toKey(this.MessageKeyCtor)
    .toValue(this.MessageValueCtor)
}
  • Design philosophy: if you want to share the same derived class, pass the same reference. In particular, with .by(), which passes an object literal, if there is an intent to reuse it, make sure to implement it so the same reference is passed. Passing a disposable (one-off) temporary object each time is acceptable (once the key is released it is removed from the WeakMap and does not leak).

Override abstract members in inflators

  • In the derived class returned by deriver, override the base's abstract member to return the binding.
  • When the overridden target is "a getter that holds the constructor of the delegate target class," name that getter [TargetClassName]Ctor (see /hoc-wire-dependencies). If the target is an undetermined abstract target, a generic name expressing the role (e.g. TargetCtor) is fine.
  • Annotate overrides with @override, in the form the JSDoc convention (/hoc-jsdoc) settles.
// OK: overriding an abstract
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл hoc-classes-inflators?

Convention for class inflator methods (binding methods): static methods that bind a value to a class and return a derived subclass. Use when writing, naming or reviewing an inflator, or when a class needs a variant configured by another class. Where inflators sit in the class body belongs to the class notation convention.

Как установить скилл hoc-classes-inflators?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hoc-classes-inflators запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить hoc-classes-inflators с