-
Notifications
You must be signed in to change notification settings - Fork 58
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
Stateful component mixin #38
Changes from all commits
ae2f09c
ab356ca
38ff97a
2754c1b
0a69fe9
c02a64b
063a1a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ typedef TProps BuilderOnlyUiFactory<TProps extends UiProps>(); | |
/// | ||
/// Extends [react.Component]. | ||
/// | ||
/// Related: [UiStatefulComponent] | ||
/// For strongly-typed state, mix in [UiStatefulMixin] or extend from [UiStatefulComponent]. | ||
abstract class UiComponent<TProps extends UiProps> extends react.Component { | ||
/// The props for the non-forwarding props defined in this component. | ||
Iterable<ConsumedProps> get consumedProps => null; | ||
|
@@ -193,16 +193,37 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
// END Typed props helpers | ||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// BEGIN Typed state helpers | ||
// | ||
|
||
/// The state Map that will be used to create the typed [state] object. | ||
/// | ||
/// Defined in [UiComponent] and not [UiStatefulMixin] to work around dart2js restriction | ||
/// on super calls in mixins <https://github.com/dart-lang/sdk/issues/23773>. | ||
Map get unwrappedState => super.state; | ||
set unwrappedState(Map value) => super.state = value; | ||
|
||
// | ||
// END Typed state helpers | ||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
} | ||
|
||
/// The basis for a stateful over_react component. | ||
/// A base class for a stateful over_react component. | ||
/// | ||
/// Includes support for strongly-typed props and state and utilities for prop and CSS classname forwarding. | ||
/// | ||
/// Extends [react.Component]. | ||
/// | ||
/// Related: [UiComponent] | ||
abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiState> extends UiComponent<TProps> { | ||
abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiState> | ||
extends UiComponent<TProps> with UiStatefulMixin<TState> {} | ||
|
||
/// A mixin that adds support for strongly-typed state to a [UiComponent]. | ||
abstract class UiStatefulMixin<TState extends UiState> | ||
// Implement react.Component instead of UiComponent so we don't run into https://github.com/dart-lang/sdk/issues/14729 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be cleaner to notate this in the doc comment instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, unless you think this information is beneficial to the audience of the doc comment. |
||
// and have to pass through UiComponent's generic parameter. | ||
implements react.Component { | ||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// BEGIN Typed state helpers | ||
|
@@ -225,11 +246,11 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat | |
} | ||
/// Equivalent to setting [unwrappedState], but needed by react-dart to effect props changes. | ||
@override | ||
set state(Map value) => super.state = value; | ||
set state(Map value) => unwrappedState = value; | ||
|
||
/// The state Map that will be used to create the typed [state] object. | ||
Map get unwrappedState => super.state; | ||
set unwrappedState(Map value) => super.state = value; | ||
Map get unwrappedState; | ||
set unwrappedState(Map value); | ||
|
||
/// Returns a typed state object backed by the specified [stateMap]. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Can't run tests in dart2js on Travis since the suite takes too long to load and times out. | ||
# Run on Smithy instead. | ||
# See https://github.com/Workiva/over_react/issues/36 | ||
|
||
set -e | ||
|
||
# Trick the test package into using Chromium instead of Chrome | ||
TMP_BIN=$(mktemp -d) | ||
ln -s "$(which chromium-browser)" "$TMP_BIN/google-chrome" | ||
export PATH="$PATH:$TMP_BIN" | ||
|
||
# Run the tests | ||
DART_FLAGS=--checked xvfb-run -s '-screen 0 1024x768x24' pub run dart_dev test -p chrome | ||
|
||
# Be sneaky and clean up our tricks | ||
rm -rf "$TMP_BIN" |
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.
Would it be fair to say that using
UiStatefulMixin
is considered best practice, instead of extendingUiStatefulComponent
? If so should we just deprecateUiStatefulComponent
?