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

[Feature]运行时转编译时 #2

Open
GrinZero opened this issue Nov 24, 2023 · 2 comments
Open

[Feature]运行时转编译时 #2

GrinZero opened this issue Nov 24, 2023 · 2 comments

Comments

@GrinZero
Copy link
Owner

GrinZero commented Nov 24, 2023

目前的render方法中部分内容完全可以在编译时处理完:

// 第一阶段添加id的这部分
    const usageDomSet = new Set<string>();
    template.replace(/{{(.*?)}}/g, (_, _key, start) => {
      const dom = findDomStr(start, template);
      usageDomSet.add(dom);
      return _;
    });
    usageDomSet.forEach((dom) => {
      let id = "";
      if (dom.indexOf("id=") === -1) {
        id = getRandomID();
        const newDom = dom.replace(">", ` id="${id}">`);
        template = template.replace(dom, newDom);
      }
    });

同时,replace本身是具体性能损耗的,考虑编译时直接收集好数据,不要重复replace

@GrinZero
Copy link
Owner Author

前提:去掉:if的rerender,换其他方式实现

@GrinZero
Copy link
Owner Author

rerender可以通过保存一份原始DOM的方式实现,每次通过clone来得到

@GrinZero GrinZero pinned this issue Nov 30, 2023
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

1 participant