Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

petritr's avatar
Level 15

computed factory - Dynamically generate computed properties

Any suggestion how to create/improve a computed factory function used to dynamically create computed getters and setter ?

I have a solutions witch is not perfect need to pass the emit to make it work.

export default function computedFactory(field, value, emit) {
    return {
        get() {
            return value;
        },
        set(newValue: string) {
            emit(`update:${field}`, newValue);
        },
    };
}
0 likes
0 replies

Please or to participate in this conversation.