lechuck.dev

solid.js 와 WebAssembly

마지막 업데이트:

solid-start

특징

solid.js 애플리케이션

개요

빌드

  1. 먼저 wasm 모듈을 빌드한 후 solid-start 디렉토리에 배포합니다.
    $ cd wasm
    $ task dist-solid-start
  2. solid-start 디렉토리에서 빌드합니다.
    $ yarn install
    $ yarn build

실행

$ cd solid-start
$ yarn start

http://localhost:3000 접속

소스코드

solid-start Routing

export default function Members() {
  const params = useParams();
  return (
    <main>
      <h3>{params.id} Members</h3>
    </main>
  );
}

solid.js store

function drawLots(p: Presentation) {
  // ...
  const selectedName = wasmDrawLots(JSON.stringify(candidates)) ?? "";
  const member = findMemberByName(selectedName);
  updatePresentation({
    ...p,
    presenterId: member.id,
  });
}

export default function Study() {
  const params = useParams();

  return (
    <main>
      <PresentationList
        presentations={presentationState.presentations}
        onDrawLots={(p) => drawLots(p)}
      />
    </main>
  );
}

Control Flow

<For>

export default function MemberList(props: Props) {
  return (
    <For each={props.members}>
      {(member) => (
        <MemberListItem
          member={member}
          onDelete={(id) => props.onDelete(id)}
          onUpdate={(update) => props.onUpdate(update)}
        />
      )}
    </For>
  );
}

<Switch>

export default function MemberListItem(props: Props) {
  const [editMode, setEditMode] = createSignal(false);
  return (
    <div>
      <Switch>
        <Match when={!editMode()}>
          {getDisplayText(props.member)}
          <Button variant="warning" onClick={() => setEditMode(!editMode())}>
            변경
          </Button>
        </Match>
        <Match when={editMode()}>
          <MemberUpdateForm
            member={props.member}
            onUpdate={(update: Member) => {
              setEditMode(false);
              props.onUpdate(update);
            }}
          />
        </Match>
      </Switch>
    </div>
  );
}

미구현 항목

소감

어쩔수 없이 react와 비교할 수 밖에 없는데, 사용해 본 소감은