Enabled using the BaseLayer features while creating the layer

This commit is contained in:
thepaperpilot 2022-03-13 18:55:47 -05:00
parent 77a3d92075
commit 496ea34a9b

View file

@ -89,15 +89,19 @@ export type GenericLayer = Replace<
}
>;
export function createLayer<T extends LayerOptions>(optionsFunc: () => T): Layer<T> {
export function createLayer<T extends LayerOptions>(
optionsFunc: (() => T) & ThisType<BaseLayer>
): Layer<T> {
return createLazyProxy(() => {
const layer = optionsFunc() as T & Partial<BaseLayer>;
const layer = {} as T & Partial<BaseLayer>;
const emitter = (layer.emitter = createNanoEvents<LayerEvents>());
layer.on = emitter.on.bind(emitter);
layer.emit = emitter.emit.bind(emitter);
layer.minimized = persistent(false);
Object.assign(layer, optionsFunc.call(layer));
processComputable(layer as T, "color");
processComputable(layer as T, "display");
processComputable(layer as T, "name");