Skip to content

createSingletonProxy

Created by Chau Tran

createSingletonProxy creates a singleton instance of a given class when a property within it is accessed, not before.

Usage

import { createSingletonProxy } from 'ngxtension/singleton-proxy';
const { proxy: worldProxy, reset: resetWorld } = createSingletonProxy(
() => new rapier.World([0, -9.81, 0]),
);
worldProxy.gravity; // rapier.World() won't be created until this point
resetWorld(); // reset the instance