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

CPLAT-8037 Implement/Expose useReducer Hook #232

Merged
merged 22 commits into from
Jan 14, 2020

Conversation

sydneyjodon-wk
Copy link
Collaborator

@sydneyjodon-wk sydneyjodon-wk commented Nov 18, 2019

Motivation

Support useReducer hook in react-dart.

Changes

  • Added ReducerHook class.
  • Added useReducer and useReducerLazy functions.
  • Wrote tests.

Please review: @kealjones-wk @aaronlademann-wf @greglittlefield-wf @joebingham-wk

Copy link
Collaborator

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

+10

@greglittlefield-wf greglittlefield-wf changed the base branch from CPLAT-8034-usestate-hook to 5.2.0-wip November 21, 2019 21:25
Copy link
Collaborator

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Some typing comments but otherwise looks perfect! Also looks like there are some merge conflicts 😢

lib/hooks.dart Outdated
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
class ReducerHook {
/// The first item of the pair returned by [React.userReducer].
Map _state;
Copy link
Collaborator

Choose a reason for hiding this comment

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

State/actions don't have to be maps, do they? If not, this class should use generics:

class ReducerHook<TState, TAActions> {
  TState _state;
  void Function(TActions ) _dispatch;
}

as should the useReucer* functions

lib/hooks.dart Outdated
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initialization>.
ReducerHook useReducerLazy<T>(Map Function(Map state, Map action) reducer, dynamic initialArg, Function init) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Init could be typed more specifically than just Function

# Conflicts:
#	example/test/function_component_test.dart
#	lib/hooks.dart
#	lib/react_client/react_interop.dart
#	test/hooks_test.dart
@aaronlademann-wf aaronlademann-wf changed the base branch from 5.2.0-wip to 5.3.0-wip December 11, 2019 22:43
# Conflicts:
#	example/test/function_component_test.dart
@greglittlefield-wf greglittlefield-wf changed the base branch from 5.3.0-wip to 5.4.0-wip January 6, 2020 18:30
# Conflicts:
#	lib/hooks.dart
#	lib/react_client/react_interop.dart
#	test/hooks_test.dart
Copy link
Collaborator

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

+10

/// final state = useReducer(reducer, {'count': 0});
///
/// return react.Fragment({}, [
/// state.state['count'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

#nit having state.state is a little confusing; I wonder if we could come up with a different name for the hook return value...

store? 😄 🤷‍♂ Nah, that's probably not better...

lib/hooks.dart Outdated
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
ReducerHook<TState, TActions, TInit> useReducer<TState, TActions, TInit>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

#nit "Action" should be singular here, so as not to confuse it with flux

Suggested change
ReducerHook<TState, TActions, TInit> useReducer<TState, TActions, TInit>(
ReducerHook<TState, TAction, TInit> useReducer<TState, TAction, TInit>(

Same on the next line and in the below function

@greglittlefield-wf
Copy link
Collaborator

+10

@greglittlefield-wf greglittlefield-wf merged commit e599130 into 5.4.0-wip Jan 14, 2020
@aaronlademann-wf aaronlademann-wf added this to the 5.4.0 milestone Jan 29, 2020
@greglittlefield-wf greglittlefield-wf deleted the CPLAT-8037-usereducer-hook branch February 16, 2022 21:53
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.

4 participants