Skip to content

@Flyweight

Shared instance pool keyed by constructor arguments.

KindRuntime
Backendslegacy, stage3
Requires generateNo

Example

ts
import { Flyweight } from 'lombok-typescript/legacy';

@Flyweight({ key: (color: string) => color })
class TreeType {
  constructor(public color: string) {}
}

const a = new TreeType('green');
const b = new TreeType('green');
console.assert(a === b);

Pools are isolated per decorated class. The first constructor arguments win for a pooled instance.

Composition notes

Do not combine with @Singleton or @Prototype — all three override constructor behavior.

Released under the MIT License.