-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
* Added a simple example app
There was a problem hiding this comment.
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:*" |
There was a problem hiding this comment.
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.
// 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; | ||
}); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
No description provided.