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

FED-1727 Remove the rest of the deprecated APIs for v7 #375

Merged
merged 8 commits into from
Oct 20, 2023
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
- SyntheticEvent members `persist` and `isPersistent`
- unconvertJsEventHandler
- APIs that were never intended for public use:
- JsPropValidator
- dartInteropStatics
- ComponentStatics(2)
- createReactDartComponentClass(2)
- InteropContextValue
- JsComponentConfig(2)
- JsError
- JsPropValidator
- React.createFactory
- ReactDartContextInternal
- ReactDartInteropStatics
- InteropContextValue
- ReactElementStore
- createReactDartComponentClass(2)
- dartInteropStatics
- markChildValidated
- markChildrenValidated

#### Other API breakages
Expand Down
2 changes: 1 addition & 1 deletion lib/react.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:react/src/react_client/private_utils.dart' show validateJsApi, v
export 'package:react/src/context.dart';
export 'package:react/src/prop_validator.dart';
export 'package:react/src/react_client/event_helpers.dart';
export 'package:react/react_client/react_interop.dart' show forwardRef2, createRef, memo, memo2;
export 'package:react/react_client/react_interop.dart' show forwardRef2, createRef, memo2;
export 'package:react/src/react_client/synthetic_event_wrappers.dart' hide NonNativeDataTransfer;
export 'package:react/src/react_client/synthetic_data_transfer.dart' show SyntheticDataTransfer;
export 'package:react/src/react_client/event_helpers.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/react_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export 'package:react/react_client/component_factory.dart'
show
listifyChildren,
unconvertJsProps,
unconvertJsEventHandler,
ReactDomComponentFactoryProxy,
ReactJsComponentFactoryProxy,
ReactDartComponentFactoryProxy,
Expand Down
11 changes: 9 additions & 2 deletions lib/react_client/bridge.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@JS()
library react.react_client.bridge;

import 'package:js/js.dart';
import 'package:meta/meta.dart';
import 'package:react/react.dart';
import 'package:react/react_client/js_backed_map.dart';
import 'package:react/react_client/react_interop.dart';
import 'package:react/src/typedefs.dart';

/// A function that returns a bridge instance for use with a given [component].
Expand Down Expand Up @@ -135,10 +137,15 @@ class Component2BridgeImpl extends Component2Bridge {
location: location,
propFullName: propFullName,
));
return error == null ? null : JsError(error.toString());
return error == null ? null : _JsError(error.toString());
}

return MapEntry(propKey, allowInterop(handlePropValidator));
})).jsObject;
}
}

@JS('Error')
class _JsError {
external _JsError(message);
}
2 changes: 1 addition & 1 deletion lib/react_client/component_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:react/src/js_interop_util.dart';
import 'package:react/src/react_client/factory_util.dart';

// ignore: deprecated_member_use_from_same_package
export 'package:react/src/react_client/factory_util.dart' show generateJsProps, unconvertJsEventHandler;
export 'package:react/src/react_client/factory_util.dart' show generateJsProps;

/// Prepares [children] to be passed to the ReactJS [React.createElement] and
/// the Dart [Component2].
Expand Down
215 changes: 1 addition & 214 deletions lib/react_client/react_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ import 'package:js/js_util.dart';
import 'package:meta/meta.dart';
import 'package:react/hooks.dart';
import 'package:react/react.dart';
import 'package:react/react_client/bridge.dart';
import 'package:react/react_client/js_backed_map.dart';
import 'package:react/react_client/component_factory.dart'
show ReactDartWrappedComponentFactoryProxy, ReactDartFunctionComponentFactoryProxy, ReactJsComponentFactoryProxy;
import 'package:react/react_client/component_factory.dart' show ReactDartWrappedComponentFactoryProxy;
import 'package:react/src/react_client/dart2_interop_workaround_bindings.dart';

typedef ReactJsComponentFactory = ReactElement Function(dynamic props, dynamic children);
@Deprecated('For internal use only. Will be made private in 7.0.0.')
typedef JsPropValidator = dynamic Function(
JsMap props, String propName, String componentName, String location, String propFullName, String secret);

// ----------------------------------------------------------------------------
// Top-level API
Expand All @@ -39,8 +34,6 @@ abstract class React {
]);
@Deprecated('For internal use only.')
external static ReactClass createClass(ReactClassConfig reactClassConfig);
@Deprecated('Use createElement instead. To be removed in 7.0.0.')
external static ReactJsComponentFactory createFactory(type);
external static ReactElement createElement(dynamic type, props, [Object? children]);
external static JsRef createRef();
external static ReactClass forwardRef(Function(JsMap props, dynamic ref) wrapperFunction);
Expand Down Expand Up @@ -280,22 +273,6 @@ ReactComponentFactoryProxy memo2(ReactComponentFactoryProxy factory,
return ReactDartWrappedComponentFactoryProxy(hoc);
}

@Deprecated('Use memo2')
ReactJsComponentFactoryProxy memo(ReactDartFunctionComponentFactoryProxy factory,
{bool Function(Map prevProps, Map nextProps)? areEqual}) {
final _areEqual = areEqual == null
? null
: allowInterop((JsMap prevProps, JsMap nextProps) {
final dartPrevProps = JsBackedMap.backedBy(prevProps);
final dartNextProps = JsBackedMap.backedBy(nextProps);
return areEqual(dartPrevProps, dartNextProps);
});
final hoc = React.memo(factory.type, _areEqual);
setProperty(hoc, 'dartComponentVersion', ReactDartComponentVersion.component2);

return ReactJsComponentFactoryProxy(hoc, alwaysReturnChildrenAsList: true);
}

abstract class ReactDom {
static Element findDOMNode(object) => ReactDOM.findDOMNode(object);
static ReactComponent render(ReactElement component, Element element) => ReactDOM.render(component, element);
Expand Down Expand Up @@ -445,16 +422,6 @@ class ReactClassConfig {
external set displayName(String value);
}

/// Interop class for the data structure at `ReactElement._store`.
///
/// Used to validate variadic children before they get to [React.createElement].
@JS()
@anonymous
class ReactElementStore {
external bool get validated;
external set validated(bool value);
}

/// A virtual DOM element representing an instance of a DOM element,
/// React component, or fragment.
///
Expand All @@ -475,8 +442,6 @@ class ReactElementStore {
@JS()
@anonymous
class ReactElement {
external ReactElementStore get _store; // ignore: unused_element

/// The type of this element.
///
/// For DOM components, this will be a [String] tagName (e.g., `'div'`, `'a'`).
Expand Down Expand Up @@ -539,26 +504,6 @@ class ReactComponent {
// Interop internals
// ----------------------------------------------------------------------------

/// A JavaScript interop class representing a value in a React JS `context` object.
///
/// Used for storing/accessing Dart [ReactDartContextInternal] objects in `context`
/// in a way that's opaque to the JS, and avoids the need to use dart2js interceptors.
///
/// __For internal/advanced use only.__
///
/// > __DEPRECATED - DO NOT USE__
/// >
/// > This API was never stable in any version of ReactJS, and was replaced with a new, incompatible context API
/// > in ReactJS 16.
/// >
/// > This will be completely removed alongside the Component class.
@Deprecated('For internal use only. Will be made private in 7.0.0.')
@JS()
@anonymous
class InteropContextValue {
external factory InteropContextValue();
}

/// A JavaScript interop class representing the return value of `createContext`.
///
/// Used for accessing Dart [Context.Provider] & [Context.Consumer] components.
Expand Down Expand Up @@ -623,30 +568,6 @@ class ReactDartComponentInternal {
final Map props;
}

/// Internal react-dart information used to proxy React JS lifecycle to Dart
/// [Component] instances.
///
/// __For internal/advanced use only.__
///
/// > __DEPRECATED - DO NOT USE__
/// >
/// > This API was never stable in any version of ReactJS, and was replaced with a new, incompatible context API
/// > in ReactJS 16.
/// >
/// > This will be completely removed alongside the Component class.
@Deprecated('For internal use only. Will be made private in 7.0.0.')
class ReactDartContextInternal {
final dynamic value;

ReactDartContextInternal(this.value);
}

/// Creates a new JS Error object with the provided message.
@JS('Error')
class JsError {
external JsError(message);
}

/// A JS variable that can be used with Dart interop in order to force returning a JavaScript `null`.
/// Use this if dart2js is possibly converting Dart `null` into `undefined`.
@JS('_jsNull')
Expand All @@ -662,45 +583,6 @@ external get jsUndefined;
@JS('_throwErrorFromJS')
external Never throwErrorFromJS(error);

/// Marks [child] as validated, as if it were passed into [React.createElement]
/// as a variadic child.
///
/// Offloaded to the JS to avoid dart2js interceptor lookup.
@JS('_markChildValidated')
external void markChildValidated(child);

/// Mark each child in [children] as validated so that React doesn't emit key warnings.
///
/// ___Only for use with variadic children.___
@Deprecated('For internal use only. Will be made private in 7.0.0.')
void markChildrenValidated(List<dynamic> children) {
for (final child in children) {
// Use `isValidElement` since `is ReactElement` doesn't behave as expected.
if (React.isValidElement(child)) {
markChildValidated(child);
}
}
}

/// Returns a new JS [ReactClass] for a component that uses
/// [dartInteropStatics] and [componentStatics] internally to proxy between
/// the JS and Dart component instances.
@JS('_createReactDartComponentClass')
@Deprecated('For internal use only. Will be made private in 7.0.0.')
external ReactClass createReactDartComponentClass(
ReactDartInteropStatics dartInteropStatics, ComponentStatics componentStatics,
[JsComponentConfig? jsConfig]);

/// Returns a new JS [ReactClass] for a component that uses
/// [dartInteropStatics] and [componentStatics] internally to proxy between
/// the JS and Dart component instances.
///
/// See `_ReactDartInteropStatics2.staticsForJs`]` for an example implementation.
@JS('_createReactDartComponentClass2')
@Deprecated('For internal use only. Will be made private in 7.0.0.')
external ReactClass createReactDartComponentClass2(JsMap dartInteropStatics, ComponentStatics2 componentStatics,
[JsComponentConfig2? jsConfig]);

@JS('React.__isDevelopment')
external bool get _inReactDevMode;

Expand All @@ -716,101 +598,6 @@ external bool get _inReactDevMode;
/// and `false` if your HTML page includes `react_prod.js` or `react_with_react_dom_prod.js`.
bool get inReactDevMode => _inReactDevMode;

/// An object that stores static methods used by all Dart components.
@JS()
@anonymous
@Deprecated('For internal use only. Will be made private in 7.0.0.')
class ReactDartInteropStatics {
external factory ReactDartInteropStatics({
Component Function(
ReactComponent jsThis,
ReactDartComponentInternal internal,
InteropContextValue context,
ComponentStatics componentStatics,
)
initComponent,
InteropContextValue Function(Component component) handleGetChildContext,
void Function(Component component) handleComponentWillMount,
void Function(Component component) handleComponentDidMount,
void Function(
Component component,
ReactDartComponentInternal nextInternal,
InteropContextValue nextContext,
)
handleComponentWillReceiveProps,
bool Function(Component component, InteropContextValue nextContext) handleShouldComponentUpdate,
void Function(Component component, InteropContextValue nextContext) handleComponentWillUpdate,
void Function(Component component, ReactDartComponentInternal prevInternal) handleComponentDidUpdate,
void Function(Component component) handleComponentWillUnmount,
dynamic Function(Component component) handleRender,
});
}

/// An object that stores static methods and information for a specific component class.
///
/// This object is made accessible to a component's JS ReactClass config, which
/// passes it to certain methods in [ReactDartInteropStatics].
///
/// See [ReactDartInteropStatics], [createReactDartComponentClass].
@Deprecated('For internal use only. Will be made private in 7.0.0.')
class ComponentStatics {
final ComponentFactory<Component> componentFactory;
ComponentStatics(this.componentFactory);
}

/// An object that stores static methods and information for a specific component class.
///
/// This object is made accessible to a component's JS ReactClass config, which
/// passes it to certain methods in `ReactDartInteropStatics2`.
///
/// See `ReactDartInteropStatics2`, [createReactDartComponentClass2].
@Deprecated('For internal use only. Will be made private in 7.0.0.')
class ComponentStatics2 {
final ComponentFactory<Component2> componentFactory;
final Component2 instanceForStaticMethods;
final Component2BridgeFactory bridgeFactory;

ComponentStatics2({
required this.componentFactory,
required this.instanceForStaticMethods,
required this.bridgeFactory,
});
}

/// Additional configuration passed to [createReactDartComponentClass]
/// that needs to be directly accessible by that JS code.
///
/// > __DEPRECATED - DO NOT USE__
/// >
/// > The `context` API that this supports was never stable in any version of ReactJS,
/// > and was replaced with a new, incompatible context API in ReactJS 16 that is exposed
/// > via the [Component2] class and is supported by [JsComponentConfig2].
/// >
/// > This will be completely removed alongside the Component class.
@Deprecated('For internal use only. Will be made private in 7.0.0.')
@JS()
@anonymous
class JsComponentConfig {
external factory JsComponentConfig({
Iterable<String>? childContextKeys,
Iterable<String>? contextKeys,
});
}

/// Additional configuration passed to [createReactDartComponentClass2]
/// that needs to be directly accessible by that JS code.
@Deprecated('For internal use only. Will be made private in 7.0.0.')
@JS()
@anonymous
class JsComponentConfig2 {
external factory JsComponentConfig2({
required List<String> skipMethods,
dynamic contextType,
JsMap defaultProps,
JsMap propTypes,
});
}

/// Information on an error caught by `componentDidCatch`.
@JS()
@anonymous
Expand Down
1 change: 1 addition & 0 deletions lib/src/react_client/component_registration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:react/react_client/react_interop.dart';
import 'package:react/react_client/component_factory.dart';

import 'package:react/src/react_client/dart_interop_statics.dart';
import 'package:react/src/react_client/internal_react_interop.dart';

import '../js_interop_util.dart';

Expand Down
1 change: 1 addition & 0 deletions lib/src/react_client/dart_interop_statics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:react/react_client/js_backed_map.dart';
import 'package:react/react_client/js_interop_helpers.dart';
import 'package:react/react_client/react_interop.dart';
import 'package:react/react_client/zone.dart';
import 'package:react/src/react_client/internal_react_interop.dart';

import 'package:react/src/react_client/private_utils.dart';
import 'package:react/src/typedefs.dart';
Expand Down
6 changes: 0 additions & 6 deletions lib/src/react_client/event_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,6 @@ extension SyntheticEventTypeHelpers on SyntheticEvent {
bool _checkEventType(List<String> types) => getProperty(this, 'type') != null && types.any((t) => type.contains(t));
bool _hasProperty(String propertyName) => hasProperty(this, propertyName);

/// Whether the event instance has been removed from the ReactJS event pool.
///
/// > See: [persist]
@Deprecated('The modern event system does not use pooling. This always returns true, and will be removed.')
bool get isPersistent => true;

/// Uses Duck Typing to detect if the event instance is a [SyntheticClipboardEvent].
bool get isClipboardEvent => _hasProperty('clipboardData') || _checkEventType(const ['copy', 'paste', 'cut']);

Expand Down
Loading
Loading