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

Qwik Optimizer #60

Closed
mhevery opened this issue Sep 29, 2021 · 0 comments
Closed

Qwik Optimizer #60

mhevery opened this issue Sep 29, 2021 · 0 comments
Assignees

Comments

@mhevery
Copy link
Contributor

mhevery commented Sep 29, 2021

Goal

Optimizer is a tool that consumes input source files, and generates bundle chunks for the application. Optimizers responsibilities are:

  • Perform Extract constant to module scope on any call site of qHook function.
  • Leave behind QRLs that point to the extracted constant.
  • Generate synthetic import modules so that bundler (rollup) can create an optimal set of chunks.
  • Run the result through the bundler to create optimal bundle chunks.

Example

The developer writes:
header.ts:

export const Header = qComponent<{ todos: Todos }, { text: string }>({
  onMount: qHook(() => ({ text: '' })),
  onRender: qHook((_, { text }) => (
      <a on:click={qHook<typeof Footer, { filter: FilterStates }>((props, _, { filter }) =>
              updateFilter(props.todos, filter)
            ).with({ filter })}
          />
  )),
});

Optimizer refactors it to something like so:

export const Header_onMount =  qHook(() => ({ text: '' }));
export const Header_onRender = qHook((_, { text }) => (
      <a on:click={qHook('chunk-pqr#Header_onRender_onClick').with({ filter })}/>
  ))
export const Header_onRender_onClick = 
  qHook<typeof Footer, { filter: FilterStates }>(
    (props, _, { filter }) => updateFilter(props.todos, filter));

export const Header = qComponent<{ todos: Todos }, { text: string }>({
  onMount: qHook('chunk-abc#Header_onMount'),
  onRender: qHook('chunk-xyz#Header_onRender'),
});

chunk-abc:

export {Header_onMount} from './header';

chunk-pqr:

export {Header_onRender_onClick} from './header';

chunk-xyz:

export {Header_onRender} from './header';

https://hackmd.io/lGHH9hjrSNq7yorN2EOBHA (old)
https://hackmd.io/KLG7PrXlQTWO6ZkBPVRAmQ (new)

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