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

Add uncurried hooks #551

Merged
merged 5 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/js/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ var Suspense = { };

var SuspenseList = { };

var Uncurried = { };

exports.Ref = Ref;
exports.Children = Children;
exports.Context = Context;
exports.Fragment = Fragment;
exports.Suspense = Suspense;
exports.SuspenseList = SuspenseList;
exports.Uncurried = Uncurried;
/* No side effect */
70 changes: 70 additions & 0 deletions src/React.re
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,76 @@ external useImperativeHandle7:
unit =
"useImperativeHandle";

module Uncurried = {
[@bs.module "react"]
external useState:
([@bs.uncurry] (unit => 'state)) =>
('state, (. ('state => 'state)) => unit) =
"useState";

[@bs.module "react"]
external useReducer:
((. 'state, 'action) => 'state, 'state) => ('state, (. 'action) => unit) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap this input back.

"useReducer";

[@bs.module "react"]
external useReducerWithMapState:
(
[@bs.uncurry] (('state, 'action) => 'state),
'initialState,
'initialState => 'state
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to your PR but I think this is unsafe. Should probably add bs.uncurry here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should go ahead and add [@bs.uncurry] to that argument on the regular useReducerWithMapState too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. As a separate PR that would be great.

) =>
('state, (. 'action) => unit) =
"useReducer";

type callback('input, 'output) = (. 'input) => 'output;

[@bs.module "react"]
external useCallback:
([@bs.uncurry] ('input => 'output)) => callback('input, 'output) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I was oblivious. Good call for keeping continuity with the other set.

Yah that issue provides a workaround but it is kind of annoying that this error exists. I don't think it should block this PR though - if the feature is never used then a better experience won't be prioritized.

"useCallback";
[@bs.module "react"]
external useCallback0:
([@bs.uncurry] ('input => 'output), [@bs.as {json|[]|json}] _) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback1:
([@bs.uncurry] ('input => 'output), array('a)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback2:
([@bs.uncurry] ('input => 'output), ('a, 'b)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback3:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback4:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback5:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback6:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback7:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) =>
callback('input, 'output) =
"useCallback";
};

type transitionConfig = {timeoutMs: int};

[@bs.module "react"]
Expand Down