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

Updated dependency #165

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class BuiltReduxGenerator extends Generator {
Future<String> generate(LibraryReader library, BuildStep buildStep) async {
final result = StringBuffer();
var hasWrittenHeaders = false;
for (final element in library.allElements) {
if (_isReduxActions(element) && element is ClassElement) {
for (final element in library.allElements.whereType<InterfaceElement>()) {
if (_isReduxActions(element)) {
if (!hasWrittenHeaders) {
hasWrittenHeaders = true;
result.writeln(_lintIgnores);
Expand All @@ -29,44 +29,44 @@ const _lintIgnores = """
// ignore_for_file: type_annotate_public_apis
""";

ActionsClass _actionsClassFromElement(ClassElement element) => ActionsClass(
ActionsClass _actionsClassFromElement(InterfaceElement element) => ActionsClass(
element.name,
_actionsFromElement(element).toSet(),
_composedActionClasses(element).toSet(),
_actionsClassFromInheritedElements(element).toSet(),
);

Iterable<ComposedActionClass> _composedActionClasses(ClassElement element) =>
element.fields.where((f) => _isReduxActions(f.type.element)).map((f) =>
Iterable<ComposedActionClass> _composedActionClasses(InterfaceElement element) =>
element.fields.where((f) => _isReduxActions(f.type.element2)).map((f) =>
ComposedActionClass(
f.name, f.type.getDisplayString(withNullability: true)));

Iterable<Action> _actionsFromElement(ClassElement element) => element.fields
Iterable<Action> _actionsFromElement(InterfaceElement element) => element.fields
.where(_isActionDispatcher)
.map((field) => _fieldElementToAction(element, field));

Iterable<ActionsClass> _actionsClassFromInheritedElements(
ClassElement element) =>
InterfaceElement element) =>
element.allSupertypes
.map((s) => s.element)
.map((s) => s.element2)
.where(_isReduxActions)
.map(_actionsClassFromElement);

Action _fieldElementToAction(ClassElement element, FieldElement field) =>
Action _fieldElementToAction(InterfaceElement element, FieldElement field) =>
Action('${element.name}-${field.name}', field.name,
_fieldType(element, field));

// hack to return the generics for the action
// this is used so action whose payloads are of generated types
// will not result in dynamic
String _fieldType(ClassElement element, FieldElement field) {
String _fieldType(InterfaceElement element, FieldElement field) {
if (field.isSynthetic) {
return _syntheticFieldType(element, field);
}
return _getGenerics(field.source!.contents.data, field.nameOffset);
}

String _syntheticFieldType(ClassElement element, FieldElement field) {
String _syntheticFieldType(InterfaceElement element, FieldElement field) {
final method = element.getGetter(field.name);
return _getGenerics(method!.source.contents.data, method.nameOffset);
}
Expand All @@ -81,25 +81,25 @@ String _getGenerics(String source, int nameOffset) {
}

bool _isReduxActions(Element? element) =>
element is ClassElement && _hasSuperType(element, 'ReduxActions');
element is InterfaceElement && _hasSuperType(element, 'ReduxActions');

bool _isActionDispatcher(FieldElement element) => element.type
.getDisplayString(withNullability: true)
.startsWith('ActionDispatcher<');

bool _hasSuperType(ClassElement classElement, String type) =>
classElement.allSupertypes
.any((interfaceType) => interfaceType.element.name == type) &&
!classElement.displayName.startsWith('_\$');
bool _hasSuperType(InterfaceElement InterfaceElement, String type) =>
InterfaceElement.allSupertypes
.any((interfaceType) => interfaceType.element2.name == type) &&
!InterfaceElement.displayName.startsWith('_\$');

String _generateActions(ClassElement element) {
String _generateActions(InterfaceElement element) {
final actionClass = _actionsClassFromElement(element);
return _generateDispatchersIfNeeded(element, actionClass) +
_actionNamesClassTemplate(actionClass);
}

String _generateDispatchersIfNeeded(
ClassElement element, ActionsClass actionsClass) =>
InterfaceElement element, ActionsClass actionsClass) =>
element.constructors.length > 1
? _actionDispatcherClassTemplate(actionsClass)
: '';
Expand Down
26 changes: 13 additions & 13 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: built_redux
version: 8.0.0
version: 9.0.1
description: A state management library written in dart that enforces immutability
homepage: https://github.com/davidmarne/built_redux
dependencies:
analyzer: ^1.0.0
build: ">=1.0.0 <3.0.0"
built_collection: ^5.0.0
built_value: ^8.0.0
source_gen: ">=0.9.4 <2.0.0"
test: ^1.16.0
analyzer: ">=4.6.0"
build: ">=2.3.1 <3.0.0"
built_collection: ">=5.1.1 <6.0.0"
built_value: ">=8.4.1 <9.0.0"
source_gen: ">=1.2.5 <2.0.0"
test: ">=0.2.0 <3.0.0"

dev_dependencies:
build_runner: ^1.7.1
build_test: ">=1.2.0 <3.0.0"
built_value_generator: ^8.0.0
build_web_compilers: ^2.7.1
workiva_analysis_options: ^1.0.0
build_runner: ">=2.2.1 <3.0.0"
build_test:
built_value_generator: ">=8.4.1 <9.0.0"
build_web_compilers: ">=3.2.0 <4.0.0"
workiva_analysis_options: ">=1.2.2 <2.0.0"

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.17.0 <3.0.0"