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

wigsill examples app & switch to pnpm #1

Merged
merged 2 commits into from
Jul 5, 2024
Merged

wigsill examples app & switch to pnpm #1

merged 2 commits into from
Jul 5, 2024

Conversation

iwoplaza
Copy link
Collaborator

@iwoplaza iwoplaza commented Jul 4, 2024

No description provided.

@iwoplaza iwoplaza self-assigned this Jul 4, 2024
@iwoplaza iwoplaza changed the title Changed package manager to pnpm. [draft] Changed package manager to pnpm. Jul 4, 2024
* Added a simple example app
@iwoplaza iwoplaza changed the title [draft] Changed package manager to pnpm. Changed package manager to pnpm. Jul 5, 2024
@iwoplaza iwoplaza changed the title Changed package manager to pnpm. wigsill examples app & switch to pnpm Jul 5, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by pnpm create vite, seem to be good defaults.

"jotai": "^2.8.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"wigsill": "workspace:*"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspace: prefix makes pnpm get the module from within the workspace (packages/wigsill in this case), not from the npm registry. * just means any version that exists.

Comment on lines +8 to +25
// using `jōtai` for a simple async resource store.
const runtimeAtom = atom(async () => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter!.requestDevice();

return new WGSLRuntime(device);
});

const sampleShaderAtom = atom(async (get) => {
const runtime = await get(runtimeAtom);

const program = new ProgramBuilder(runtime, sampleShader).build({
bindingGroup: 0,
shaderStage: GPUShaderStage.COMPUTE,
});

return program.code;
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jotai allows us to create async (or not) resources that depend on each other, in this case sampleShaderAtom depends on runtimeAtom. The value of sampleShaderAtom will be recalculated each time runtimeAtom is changed. runtimeAtom has no dependencies, so only computes once.

});

function ShaderCodeView() {
const resolvedCode = useAtomValue(sampleShaderAtom);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the atom is asynchronous, React will suspend rendering this component until the promise resolves. It will show the nearest parent 's fallback.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a helper React hook for creating stable event handler functions.

@iwoplaza iwoplaza requested a review from mhawryluk July 5, 2024 10:41
Copy link
Collaborator

@mhawryluk mhawryluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ^^

@iwoplaza iwoplaza requested a review from reczkok July 5, 2024 10:41
Copy link
Collaborator

@reczkok reczkok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@iwoplaza iwoplaza merged commit 4577770 into main Jul 5, 2024
@iwoplaza iwoplaza deleted the pnpm-migration branch July 5, 2024 10:42
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

Successfully merging this pull request may close these issues.

3 participants