Skip to content

Commit

Permalink
Revert "Initial integration tests"
Browse files Browse the repository at this point in the history
This reverts commit b19542c.
  • Loading branch information
sydneyjodon-wk committed Jul 17, 2020
1 parent 49d1f5e commit 27bc400
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 436 deletions.
27 changes: 0 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -846,33 +846,6 @@ that you get for free from OverReact, you're ready to start building your own cu
}
}
```

* #### Function Component Boilerplate

```dart
import 'package:over_react/over_react.dart';
part 'foo_component.over_react.g.dart';
UiFactory<FooProps> Foo = uiFunctionComponent((props) {
// Return the rendered component contents here.
// The `props` variable is typed; no need for string keys!
},
// The generated props config will match the factory name.
$FooPropsConfig,
initStatics: (statics) {
statics.defaultProps = (statics.newProps()
// Cascade default props here.
..isDisabled = false
..items = []
);
});

mixin FooProps on UiProps {
// Props go here, declared as fields:
bool isDisabled;
Iterable<String> items;
}
```

&nbsp;

Expand Down
13 changes: 7 additions & 6 deletions lib/src/builder/parsing/declarations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import 'package:analyzer/dart/ast/ast.dart';
import 'package:meta/meta.dart';
import 'package:over_react/over_react.dart';

import 'ast_util.dart';
import 'error_collection.dart';
Expand Down Expand Up @@ -303,13 +302,15 @@ class PropsMapViewOrFunctionComponentDeclaration extends BoilerplateDeclaration
}) : super(Version.v4_mixinBased);
}

/// A boilerplate declaration for a function component declared using
/// the new mixin-based boilerplate that does not need a generated props config.
/// A boilerplate declaration for a generic function component declared using
/// the new mixin-based boilerplate.
///
/// This means it was declared using UiProps or a custom [PropsFactory].
/// This is similar to [PropsMapViewOrFunctionComponentDeclaration], but it does
/// not need a corresponding props mixin because it uses UiProps and no
/// code is generated.
///
/// See [BoilerplateDeclaration] for more info.
class FunctionComponentDeclaration extends BoilerplateDeclaration
class GenericFunctionComponentDeclaration extends BoilerplateDeclaration
with _TypedMapMixinShorthandDeclaration {
final BoilerplateFactory factory;

Expand All @@ -319,7 +320,7 @@ class FunctionComponentDeclaration extends BoilerplateDeclaration
@override
get type => DeclarationType.genericFunctionComponentDeclaration;

FunctionComponentDeclaration({
GenericFunctionComponentDeclaration({
@required this.factory,
}) : super(Version.v4_mixinBased);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/parsing/declarations_from_members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Iterable<BoilerplateDeclaration> getBoilerplateDeclarations(
getPropsNameFromFunctionComponent(factory) == 'UiProps' || !hasConfigArg(factory));
for (final factory in genericFactories) {
consume(factory);
yield FunctionComponentDeclaration(factory: factory);
yield GenericFunctionComponentDeclaration(factory: factory);
}

for (final propsClassOrMixin in allUnusedProps) {
Expand Down
50 changes: 20 additions & 30 deletions lib/src/component_declaration/function_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ import 'package:react/react.dart' as react;
import 'package:react/react_client.dart';
import 'package:react/react_client/js_backed_map.dart';

export 'component_type_checking.dart'
show isComponentOfType, isValidElementOfType;
export 'component_type_checking.dart' show isComponentOfType, isValidElementOfType;

UiFactory<T> uiFunctionComponent<T extends UiProps>(
FunctionComponent<T> functionComponent,
FunctionComponentConfig<T> config, {
PropsFactory<T> propsFactory,
String displayName,
void Function(UiFunctionComponentStatics<T>) initStatics,
}) {
dynamic Function(T props) functionComponent,
FunctionComponentConfig<T> config, {
PropsFactory<T> propsFactory,
String displayName,
void Function(UiFunctionComponentStatics<T>) initStatics,
}) {
if (config != null) {
if (propsFactory != null) {
throw ArgumentError('propsFactory cannot be used along with config');
}
if (propsFactory != null) throw ArgumentError('propsFactory cannot be used along with config');
propsFactory = config.propsFactory;
displayName ??= config.componentName;
}
Expand All @@ -52,15 +49,18 @@ UiFactory<T> uiFunctionComponent<T extends UiProps>(
if (initStatics != null) {
final statics = UiFunctionComponentStatics<T>._(
newProps: () => propsFactory.jsMap(JsBackedMap()),
keyFor: (accessProps) => getPropKey(accessProps, propsFactory.map),);
keyFor: (accessProps) => getPropKey(accessProps, propsFactory.map)
);
initStatics(statics);

if (statics.defaultProps != null) {
factory = react.registerFunctionComponent(_uiFunctionComponentWrapper,
displayName: displayName, defaultProps: statics.defaultProps);
}
// fixme need to implement in react-dart
if (statics.propTypes != null) {}
if (statics.propTypes != null) {

}
} else {
// FIXME DartFunctionComponent should be JsBackedMap?
factory = react.registerFunctionComponent(_uiFunctionComponentWrapper,
Expand All @@ -71,12 +71,9 @@ UiFactory<T> uiFunctionComponent<T extends UiProps>(
// todo allow passing in of custom uiFactory/typedPropsFactory
// TODO make it easier to pass in parts of generatedInfo
if (T != UiProps && T != GenericUiProps) {
throw ArgumentError(
'config.propsFactory must be provided when using custom props classes');
throw ArgumentError('config.propsFactory must be provided when using custom props classes');
}
propsFactory = PropsFactory.fromUiFactory(
([backingMap]) => GenericUiProps(factory, backingMap))
as PropsFactory<T>;
propsFactory = PropsFactory.fromUiFactory(([backingMap]) => GenericUiProps(factory, backingMap)) as PropsFactory<T>;
}

T _uiFactory([Map backingMap]) {
Expand All @@ -91,17 +88,14 @@ UiFactory<T> uiFunctionComponent<T extends UiProps>(

return builder..componentFactory = factory;
}

return _uiFactory;
}

String getFunctionName(Function function) {
if (function == null) throw ArgumentError.notNull('f');

final functionName = getProperty(function, 'name');
if (functionName.toString().isNotEmpty && functionName != null) {
return functionName;
}
if(functionName.toString().isNotEmpty && functionName != null) return functionName;

return 'UiFunctionComponent';
}
Expand All @@ -120,8 +114,8 @@ class GenericUiProps extends UiProps {
@override
final Map props;

GenericUiProps(ReactComponentFactoryProxy componentFactory, [Map props])
: this.props = props ?? JsBackedMap() {
GenericUiProps(ReactComponentFactoryProxy componentFactory, [Map props]) :
this.props = props ?? JsBackedMap() {
this.componentFactory = componentFactory;
}

Expand All @@ -132,9 +126,7 @@ class GenericUiProps extends UiProps {
bool get $isClassGenerated => true;
}

typedef FunctionFactoryFactory<T extends UiProps> = UiFactory<T> Function(
ReactDartFunctionComponentFactoryProxy);
typedef dynamic FunctionComponent<T extends UiProps>(T props);
typedef FunctionFactoryFactory<T extends UiProps> = UiFactory<T> Function(ReactDartFunctionComponentFactoryProxy);

@protected
class FunctionComponentConfig<T extends UiProps> {
Expand All @@ -155,7 +147,5 @@ class PropsFactory<T extends UiProps> {
@required this.jsMap,
});

PropsFactory.fromUiFactory(UiFactory<T> factory)
: this.map = factory,
this.jsMap = factory;
PropsFactory.fromUiFactory(UiFactory<T> factory) : this.map = factory, this.jsMap = factory;
}

This file was deleted.

Loading

0 comments on commit 27bc400

Please sign in to comment.