-
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
UIP-1953 Sync changes from OverReact source #40
Changes from 1 commit
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import 'package:over_react/over_react.dart' show | |
prettyPrintMap, | ||
unindent, | ||
PropError; | ||
|
||
import 'package:over_react/src/component_declaration/component_type_checking.dart'; | ||
import 'package:react/react.dart' as react; | ||
import 'package:react/react_client.dart'; | ||
|
@@ -85,14 +86,20 @@ typedef TProps UiFactory<TProps extends UiProps>([Map backingProps]); | |
/// For use as a Function variable type when the `backingProps` argument is not required. | ||
typedef TProps BuilderOnlyUiFactory<TProps extends UiProps>(); | ||
|
||
/// The basis for a over_react component. | ||
typedef dynamic _RefTypedef(String ref); | ||
|
||
/// The basis for a over_react component, extending [react.Component]. (Successor to [BaseComponent]). | ||
/// | ||
/// Includes support for strongly-typed props and utilities for prop and CSS classname forwarding. | ||
/// | ||
/// Extends [react.Component]. | ||
/// | ||
/// Related: [UiStatefulComponent] | ||
abstract class UiComponent<TProps extends UiProps> extends react.Component { | ||
/// Returns the component of the specified [ref]. | ||
/// > `react.Component` if it is a Dart component | ||
/// > DOM node if it is a DOM component. | ||
/// | ||
/// Overridden for strong typing. | ||
@override | ||
_RefTypedef get ref => super.ref; | ||
|
||
/// The props for the non-forwarding props defined in this component. | ||
Iterable<ConsumedProps> get consumedProps => null; | ||
|
||
|
@@ -124,12 +131,12 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
void validateRequiredProps(Map appliedProps) { | ||
consumedProps?.forEach((ConsumedProps consumedProps) { | ||
consumedProps.props.forEach((PropDescriptor prop) { | ||
if (!prop.isRequired) return; | ||
if (prop.isNullable && appliedProps.containsKey(prop.key)) return; | ||
if (!prop.isNullable && appliedProps[prop.key] != null) return; | ||
if (!prop.isRequired) return; | ||
if (prop.isNullable && appliedProps.containsKey(prop.key)) return; | ||
if (!prop.isNullable && appliedProps[prop.key] != null) return; | ||
|
||
throw new PropError.required(prop.key, prop.errorMessage); | ||
}); | ||
throw new PropError.required(prop.key, prop.errorMessage); | ||
}); | ||
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. #nit looks like this was fixed in over_react after the code diverged |
||
}); | ||
} | ||
|
||
|
@@ -186,6 +193,7 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
TProps typedPropsFactory(Map propsMap); | ||
|
||
/// Returns a typed props object backed by a new Map. | ||
/// | ||
/// Convenient for use with [getDefaultProps]. | ||
TProps newProps() => typedPropsFactory({}); | ||
|
||
|
@@ -195,11 +203,11 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
// ---------------------------------------------------------------------- | ||
} | ||
|
||
/// The basis for a stateful over_react component. | ||
/// /// The basis for a stateful over_react component. | ||
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. #nit looks like this was fixed in over_react after the code diverged |
||
/// | ||
/// Includes support for strongly-typed props and state and utilities for prop and CSS classname forwarding. | ||
/// | ||
/// Extends [react.Component]. | ||
/// Extends [react.Component] | ||
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. #nit looks like this was fixed in over_react after the code diverged |
||
/// | ||
/// Related: [UiComponent] | ||
abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiState> extends UiComponent<TProps> { | ||
|
@@ -232,7 +240,6 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat | |
set unwrappedState(Map value) => super.state = value; | ||
|
||
/// Returns a typed state object backed by the specified [stateMap]. | ||
/// | ||
/// Required to properly instantiate the generic [TState] class. | ||
TState typedStateFactory(Map stateMap); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,13 @@ abstract class FluxUiProps<ActionsT, StoresT> extends UiProps { | |
ActionsT get actions => props[_actionsPropKey] as ActionsT; // ignore: avoid_as | ||
set actions(ActionsT value) => props[_actionsPropKey] = value; | ||
|
||
/// The prop defined by [StoresT]. | ||
/// The prop defined by [StoresT]. This object should either be an | ||
/// instance of [Store] or should provide access to one or more [Store]s. | ||
/// | ||
/// This object should either be an instance of [Store] or should provide access to one or more [Store]s. | ||
/// | ||
/// __Instead of storing state within this component via `setState`, it is recommended that data be | ||
/// pulled directly from these stores.__ This ensures that the data being used is always up to date | ||
/// and leaves the state management logic to the stores. | ||
/// **Instead of storing state within this component via [setState], it is | ||
/// recommended that data be pulled directly from these stores.** This ensures | ||
/// that the data being used is always up to date and leaves the state | ||
/// management logic to the stores. | ||
/// | ||
/// If this component only needs data from a single [Store], then [StoresT] | ||
/// should be an instance of [Store]. This allows the default implementation | ||
|
@@ -36,30 +36,28 @@ abstract class FluxUiProps<ActionsT, StoresT> extends UiProps { | |
/// If this component needs data from multiple [Store] instances, then | ||
/// [StoresT] should be a class that provides access to these multiple stores. | ||
/// Then, you can explicitly select the [Store] instances that should be | ||
/// listened to by overriding [_FluxComponentMixin.redrawOn]. | ||
/// listened to by overriding [redrawOn]. | ||
StoresT get store => props[_storePropKey] as StoresT; // ignore: avoid_as | ||
set store(StoresT value) => props[_storePropKey] = value; | ||
} | ||
|
||
/// Builds on top of [UiComponent], adding w_flux integration, much like the [FluxComponent] in w_flux. | ||
/// | ||
/// * Flux components are responsible for rendering application views and turning | ||
/// user interactions and events into [Action]s. | ||
/// * Flux components can use data from one or many [Store] instances to define | ||
/// the resulting component. | ||
/// Flux components are responsible for rendering application views and turning | ||
/// user interactions and events into [Action]s. Flux components can use data | ||
/// from one or many [Store] instances to define the resulting component. | ||
/// | ||
/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. | ||
/// Use with the over_react transformer via the `@Component()` ([Component]) annotation. | ||
abstract class FluxUiComponent<TProps extends FluxUiProps> extends UiComponent<TProps> | ||
with _FluxComponentMixin<TProps>, BatchedRedraws {} | ||
|
||
/// Builds on top of [UiStatefulComponent], adding `w_flux` integration, much like the [FluxComponent] in w_flux. | ||
/// Builds on top of [StatefulUiComponent], adding w_flux integration, much like the [FluxComponent] in w_flux. | ||
/// | ||
/// * Flux components are responsible for rendering application views and turning | ||
/// user interactions and events into [Action]s. | ||
/// * Flux components can use data from one or many [Store] instances to define | ||
/// the resulting component. | ||
/// Flux components are responsible for rendering application views and turning | ||
/// user interactions and events into [Action]s. Flux components can use data | ||
/// from one or many [Store] instances to define the resulting component. | ||
/// | ||
/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. | ||
/// Use with the over_react transformer via the `@Component()` ([Component]) annotation. | ||
abstract class FluxUiStatefulComponent<TProps extends FluxUiProps, TState extends UiState> | ||
extends UiStatefulComponent<TProps, TState> | ||
with _FluxComponentMixin<TProps>, BatchedRedraws {} | ||
|
@@ -70,19 +68,15 @@ abstract class FluxUiStatefulComponent<TProps extends FluxUiProps, TState extend | |
abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements BatchedRedraws { | ||
TProps get props; | ||
|
||
/// List of store subscriptions created when the component mounts. | ||
/// | ||
/// These subscriptions are canceled when the component is unmounted. | ||
/// List of store subscriptions created when the component mounts. These | ||
/// subscriptions are canceled when the component is unmounted. | ||
List<StreamSubscription> _subscriptions = []; | ||
|
||
void componentWillMount() { | ||
/// Subscribe to all applicable stores. | ||
/// | ||
/// [Store]s returned by [redrawOn] will have their triggers mapped directly to this components | ||
/// redraw function. | ||
/// | ||
/// [Store]s included in the [getStoreHandlers] result will be listened to and wired up to their | ||
/// respective handlers. | ||
componentWillMount() { | ||
// Subscribe to all applicable stores. Stores returned by `redrawOn()` will | ||
// have their triggers mapped directly to this components redraw function. | ||
// Stores included in the `getStoreHandlers()` result will be listened to | ||
// and wired up to their respective handlers. | ||
Map<Store, StoreHandler> handlers = new Map.fromIterable(redrawOn(), | ||
value: (_) => (_) => redraw())..addAll(getStoreHandlers()); | ||
|
||
|
@@ -92,8 +86,8 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
}); | ||
} | ||
|
||
void componentWillUnmount() { | ||
// Ensure that unmounted components don't batch render | ||
componentWillUnmount() { | ||
// ensure that unmounted components don't batch render | ||
shouldBatchRedraw = false; | ||
|
||
// Cancel all store subscriptions. | ||
|
@@ -105,7 +99,6 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
} | ||
|
||
/// Define the list of [Store] instances that this component should listen to. | ||
/// | ||
/// When any of the returned [Store]s update their state, this component will | ||
/// redraw. | ||
/// | ||
|
@@ -128,9 +121,8 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
} | ||
|
||
/// If you need more fine-grained control over store trigger handling, | ||
/// override this method to return a Map of stores to handlers. | ||
/// | ||
/// Whenever a store in the returned map triggers, the respective handler will be called. | ||
/// override this method to return a Map of stores to handlers. Whenever a | ||
/// store in the returned map triggers, the respective handler will be called. | ||
/// | ||
/// Handlers defined here take precedence over the [redrawOn] handling. | ||
/// If possible, however, [redrawOn] should be used instead of this in order | ||
|
@@ -140,9 +132,9 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
return {}; | ||
} | ||
|
||
/// Register a [subscription] that should be canceled when the component unmounts. | ||
/// | ||
/// Cancellation will be handled automatically by [componentWillUnmount]. | ||
/// Register a [subscription] that should be canceled when the component | ||
/// unmounts. Cancellation will be handled automatically by | ||
/// [componentWillUnmount]. | ||
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. Seems like the version of this file was more up to date in over_react (i.e., these changes should be discarded) |
||
void addSubscription(StreamSubscription subscription) { | ||
_subscriptions.add(subscription); | ||
} | ||
|
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.
I thought we removed these redeclaration of
ref
s when we added the typing to react-dart.