Skip to content

Commit

Permalink
Add Component2 / AbstractComponent2 annotations
Browse files Browse the repository at this point in the history
+ And deprecate the v1 ones
  • Loading branch information
aaronlademann-wf committed May 1, 2019
1 parent d600f4e commit 861fcdf
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/src/component_declaration/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class State implements TypedMap {
/// }
///
/// Must be accompanied by a [Factory] and [Props] declaration.
///
/// __Deprecated.__ Use the [Component2] annotation alongside `UiComponent2` / `UiStatefulComponent2` instead.
@Deprecated('4.0.0')
class Component {
/// Whether the component clones or passes through its children and needs to be
/// treated as if it were the wrapped component when passed in to [over_react.isComponentOfType].
Expand Down Expand Up @@ -104,6 +107,51 @@ class Component {
});
}

/// Annotation used with the `over_react` builder to declare a `UiComponent2` class for a component.
///
/// @Component2()
/// class FooComponent extends UiComponent2<FooProps> {
/// render() => Dom.div()(props.bar);
/// }
///
/// Must be accompanied by a [Factory] and [Props] declaration.
class Component2 implements Component {
/// Whether the component clones or passes through its children and needs to be
/// treated as if it were the wrapped component when passed in to `isComponentOfType`.
@override
final bool isWrapper;

/// The component class of this component's "parent type".
///
/// Used to enable inheritance in component type-checking in `isComponentOfType`.
///
/// E.g., if component `Bar` is a subtype of component `Foo`:
///
/// @Factory()
/// UiFactory<...> Foo = _$Foo;
/// ...
/// @Component2()
/// class FooComponent ... {...}
///
/// @Factory()
/// UiFactory<...> Bar = _$Bar;
/// ...
/// @Component2(subtypeOf: FooComponent)
/// class BarComponent ... {...}
///
/// then:
///
/// isComponentOfType(Bar()(), Bar); // true (due to normal type-checking)
/// isComponentOfType(Bar()(), Foo); // true (due to parent type-checking)
@override
final Type subtypeOf;

const Component2({
this.isWrapper: false,
this.subtypeOf
});
}

/// Annotation used with the `over_react` builder to declare an abstract [UiProps] class for an abstract component.
///
/// Props are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs.
Expand Down Expand Up @@ -140,10 +188,21 @@ class AbstractState implements TypedMap {
///
/// @AbstractComponent()
/// abstract class QuxComponent<TProps extends QuxProps> extends UiComponent<TProps> {}
///
/// __Deprecated.__ Use the [AbstractComponent2] annotation alongside `UiComponent2` / `UiStatefulComponent2` instead.
@Deprecated('4.0.0')
class AbstractComponent {
const AbstractComponent();
}

/// Annotation used with the `over_react` builder to declare an abstract `UiComponent2` class for an abstract component.
///
/// @AbstractComponent2()
/// abstract class FooComponent<TProps extends QuxProps> extends UiComponent2<TProps> {}
class AbstractComponent2 implements AbstractComponent {
const AbstractComponent2();
}

/// Annotation used with the `over_react` builder to declare a mixin for use in a [UiProps] class.
///
/// Props are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/component_declaration/builder_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ mixin _GeneratedUiComponent2Stubs<TProps extends UiProps>
TProps typedPropsFactoryJs(JsBackedMap propsMap) => throw new UngeneratedError(member: #typedPropsFactoryJs);
}

/// See: [component_base.UiComponent2]
///
/// Use with the over_react builder via the `@Component2()` ([annotations.Component2]) annotation.
abstract class UiComponent2<TProps extends UiProps>
extends component_base.UiComponent2<TProps>
with
Expand All @@ -142,6 +145,9 @@ abstract class UiComponent2<TProps extends UiProps>
}
}

/// See: [component_base.UiStatefulComponent2]
///
/// Use with the over_react builder via the `@Component2()` ([annotations.Component2]) annotation.
abstract class UiStatefulComponent2<TProps extends UiProps, TState extends UiState>
extends component_base.UiStatefulComponent2<TProps, TState>
with
Expand Down

0 comments on commit 861fcdf

Please sign in to comment.