Skip to content

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

Merged
merged 2 commits into from
Aug 14, 2019
Merged

Hook creation and aliasing/newtyping #9

merged 2 commits into from
Aug 14, 2019

Conversation

maddie927
Copy link
Member

@maddie927 maddie927 commented Aug 14, 2019

Exposes the tools needed to create custom hooks, both in PS and FFI

in
runEffectFn2 unsafeSetDisplayName name c

unsafeDiscardRenderEffects :: forall x y a. Render x y a -> Effect a
unsafeDiscardRenderEffects = unsafeCoerce
Copy link
Member Author

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

Choose a reason for hiding this comment

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

Also AFAIK unsafeCoerces are erased at compile-time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh neat

Copy link
Member Author

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) _
Copy link
Member Author

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
Copy link
Member Author

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..

@maddie927 maddie927 merged commit ea1134b into master Aug 14, 2019
@maddie927 maddie927 deleted the hook-creation branch August 14, 2019 20:44
maddie927 added a commit that referenced this pull request Aug 14, 2019
Hook creation and aliasing/newtyping
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.

2 participants