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

app.show 是否支持传参,更新 props #626

Open
2 tasks done
realyuyanan opened this issue Jun 27, 2023 · 3 comments
Open
2 tasks done

app.show 是否支持传参,更新 props #626

realyuyanan opened this issue Jun 27, 2023 · 3 comments

Comments

@realyuyanan
Copy link

Clear and concise description of the problem

每次点击都会更新参数,app.show 是否可以支持传参。

  let app;
  const initSubApp = async (id) => {
    app = await Garfish.loadApp('app2', {
      entry: 'http://localhost:3001',
      basename: '/test',
      domGetter: '#container',
      props: {
        id
      },
    });
    app.mount();
  }
  const handleClick = (id) => {
    if (!app) {
      initSubApp(id);
      return
    }
    app.show(id);
  };

Suggested solution

app.show 支持传参

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@zhoushaw
Copy link
Member

zhoushaw commented Jun 28, 2023

感觉你可以考虑

  let app;
  let props = {
    id: 1
  };
  const initSubApp = async (id) => {
    app = await Garfish.loadApp('app2', {
      entry: 'http://localhost:3001',
      basename: '/test',
      domGetter: '#container',
      props,
    });
    app.mount();
  }
  const handleClick = (id) => {
    if (!app) {
      initSubApp(id);
      return
    }
    props.id = id;
    app.show();
  };

@realyuyanan
Copy link
Author

感觉你可以考虑

  let app;
  let props = {
    id: 1
  };
  const initSubApp = async (id) => {
    app = await Garfish.loadApp('app2', {
      entry: 'http://localhost:3001',
      basename: '/test',
      domGetter: '#container',
      props,
    });
    app.mount();
  }
  const handleClick = (id) => {
    if (!app) {
      initSubApp(id);
      return
    }
    props.id = id;
    app.show();
  };

好像不行.

@zhoushaw
Copy link
Member

  let app;
  let id = 1;
  let getId = ()=> id;
  let props = {
    getId
  };
  const initSubApp = async (id) => {
    app = await Garfish.loadApp('app2', {
      entry: 'http://localhost:3001',
      basename: '/test',
      domGetter: '#container',
      props,
    });
    app.mount();
  }
  const handleClick = (id) => {
    if (!app) {
      initSubApp(id);
      return
    }
    id = id;
    app.show();
  };

你尝试通过一个函数去获取值,这个值维护在主应用上面,上面的方式确实不行,因为被 Garfish 初始化参数的时候拷贝了,函数是不会拷贝的,你把值变更后子应用通过函数可以获取到最新的值

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

No branches or pull requests

2 participants