-
-
Notifications
You must be signed in to change notification settings - Fork 22
feat(@typegpu/react): Implement useUniformValue hook #1694
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
feat(@typegpu/react): Implement useUniformValue hook #1694
Conversation
pkg.pr.new packages
benchmark commit |
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: This value needs to be stable | ||
const uniformValue = useMemo(() => { | ||
let currentValue = initialValue; |
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.
Schemas should generally be callable, in which case they return an initial value that matches that schema.
let currentValue = initialValue; | |
let currentValue = initialValue ?? schema(); |
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.
Thanks for pointing that out! However, with current implementation:
export function useUniformValue<
TSchema extends d.AnyWgslData,
TValue extends d.Infer<TSchema>,
>(
schema: ValidateUniformSchema<TSchema>,
initialValue?: TValue | undefined,
): UniformValue<TSchema, TValue> {
schema is not callable:
This expression is not callable.
Not all constituents of type 'AnyWgslData | `(Error) ${string}`' are callable.
Type 'U16' has no call signatures.ts(2349)
I'm wondering how can I alter this to simplify the logic.
get value() { | ||
return currentValue; | ||
}, | ||
set value(newValue: TValue | undefined) { | ||
currentValue = newValue; | ||
if (newValue !== undefined) { | ||
uniformBuffer.write(newValue); | ||
} | ||
}, |
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.
Because of the previous comment, we don't have to worry about undefined.
get value() { | |
return currentValue; | |
}, | |
set value(newValue: TValue | undefined) { | |
currentValue = newValue; | |
if (newValue !== undefined) { | |
uniformBuffer.write(newValue); | |
} | |
}, | |
get value() { | |
return currentValue; | |
}, | |
set value(newValue: TValue) { | |
currentValue = newValue; | |
uniformBuffer.write(newValue); | |
}, |
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.
Thanks a lot for this 🙏
As for the comments, I'll sort it out in the original branch
Changes
useUniformValue
hookCloses #1689