-
Notifications
You must be signed in to change notification settings - Fork 33
Hook creation and aliasing/newtyping #9
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
Conversation
in | ||
runEffectFn2 unsafeSetDisplayName name c | ||
|
||
unsafeDiscardRenderEffects :: forall x y a. Render x y a -> Effect a | ||
unsafeDiscardRenderEffects = unsafeCoerce |
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.
Opted to keep this an unsafeCoerce
instead of exporting another unsafe function from Internal
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.
Also AFAIK unsafeCoerce
s are erased at compile-time.
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.
Oh neat
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.
Well, probably at purs bundle
time, but we use webpack :)
newtype UseAff key a hooks | ||
= UseAff (UseEffect key (UseState (Result a) hooks)) | ||
|
||
derive instance ntUseAff :: Newtype (UseAff key a hooks) _ |
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.
This newtype plus the newtypeHook
below results in UseAff
appearing in type holes/errors rather than the inner type
-- | may cause them to be run many times by React. | ||
-- | You should almost always prefer `useEffect`! | ||
unsafeRenderEffect :: forall a. Effect a -> Pure a | ||
unsafeRenderEffect = Render |
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.
These two unsafe functions are named unsafe because of the effects they might produce if used incorrectly, but I'm not sure if that actually makes them unsafe..
Hook creation and aliasing/newtyping
Exposes the tools needed to create custom hooks, both in PS and FFI