Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve defineExpose() #7890

Open
silentmantra opened this issue Mar 13, 2023 · 1 comment
Open

Improve defineExpose() #7890

silentmantra opened this issue Mar 13, 2023 · 1 comment
Labels
✨ feature request New feature or request

Comments

@silentmantra
Copy link

silentmantra commented Mar 13, 2023

What problem does this feature solve?

I would like to propose 2 things to defineExpose.

  1. [DONE fix(compiler-sfc): rename expose variable name #7949] Make expose variable more cryptic like __expose (like props) so we could use another expose variable (in my case I had to use exposed:
const _sfc_main$k = {
  __name: 'DialogComponent',
  setup(__props, { expose }) {


const exposed = {};
expose(exposed);
  1. Nice feature of the expose that you can add to it later like in onMounted() when we have our DOM ready:
    Object.assign(exposed, {
        showModal: async loader => {
            if (loader) {
                ({ default: component.value } = await loader());
            }
            $dialog[0].showModal();
        },
        close: () => $dialog[0].close()
    });

To make the syntax shorter in the first item of this proposal I suggest to return the exposed object from the expose function:

function createSetupContext(instance) {
    const expose = exposed => {
        // return here
        return (instance.exposed = exposed || {});
    };
    let attrs;
    {
        return {
            get attrs() {
                return attrs || (attrs = createAttrsProxy(instance));
            },
            slots: instance.slots,
            emit: instance.emit,
            expose
        };
    }
}

so our exposed object could be declared like that giving we solved the both problems:

const expose = defineExpose();
// later add props to the expose for example in `onMounted()`

What does the proposed API look like?

  1. Encrypt encode script setup parameter generated with defineExpose()
  2. Return from the expose function the exposed object to use it later;
@silentmantra silentmantra added the ✨ feature request New feature or request label Mar 13, 2023
yyx990803 pushed a commit that referenced this issue Mar 28, 2023
…xpose` (#7949)

rename `expose` to `__expose` to avoid duplicate identifier

relate #7890
IAmSSH pushed a commit to IAmSSH/core that referenced this issue May 14, 2023
…xpose` (vuejs#7949)

rename `expose` to `__expose` to avoid duplicate identifier

relate vuejs#7890
@sxzz
Copy link
Member

sxzz commented Jun 11, 2023

The first one is resolved in #7949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants