Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/pr-check-annotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.5
flutter-version: 3.41.9
channel: stable
cache: true
- name: Check out repository code
Expand All @@ -36,4 +36,4 @@ jobs:
run: cd packages/reactive_forms_annotations && flutter analyze --no-fatal-infos

- name: reactive_forms_annotations => code formatting
run: cd packages/reactive_forms_annotations && dart format --set-exit-if-changed lib
run: cd packages/reactive_forms_annotations && dart format --set-exit-if-changed lib
4 changes: 2 additions & 2 deletions .github/workflows/pr-check-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.5
flutter-version: 3.41.9
channel: stable
cache: true
- name: Check out repository code
Expand All @@ -42,4 +42,4 @@ jobs:
# run: cd packages/reactive_forms_generator/example && flutter pub get && dart format --set-exit-if-changed lib

- name: reactive_forms_generator => example => test
run: cd packages/reactive_forms_generator/example && flutter test
run: cd packages/reactive_forms_generator/example && flutter test
4 changes: 2 additions & 2 deletions .github/workflows/pr-check-generator-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.5
flutter-version: 3.41.9
channel: stable
cache: true
- name: Check out repository code
Expand All @@ -33,4 +33,4 @@ jobs:
run: melos bs

- name: reactive_forms_generator => Code generation tests
run: cd packages/generator_tests && dart test && cd ../
run: cd packages/generator_tests && dart test && cd ../
4 changes: 2 additions & 2 deletions .github/workflows/pr-check-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.5
flutter-version: 3.41.9
channel: stable
cache: true
- name: Check out repository code
Expand All @@ -36,4 +36,4 @@ jobs:
run: flutter analyze --no-fatal-infos

- name: code formatting
run: dart format --set-exit-if-changed lib
run: dart format --set-exit-if-changed lib
9 changes: 2 additions & 7 deletions packages/generator_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ resolution: workspace

dependencies:
build: ^4.0.1
source_gen: ^4.0.1
source_gen: ^4.1.2
path: ^1.8.2
build_runner: ^2.10.1
code_builder: ^4.11.0
dart_style: ^3.1.2
dart_style: ^3.1.3
recase: ^4.1.0
reactive_forms_annotations:
path: ../reactive_forms_annotations
Expand All @@ -43,8 +43,3 @@ dev_dependencies:
reactive_forms_generator:
path: ../reactive_forms_generator
flutter_lints: ^6.0.0

dependency_overrides:
analyzer: 8.2.0
_fe_analyzer_shared: 89.0.0
test_core: 0.6.8
88 changes: 33 additions & 55 deletions packages/generator_tests/test/doc/array_nullable_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class _ArrayNullableOFormBuilderState extends State<ArrayNullableOFormBuilder> {
ArrayNullableOForm.formElements(widget.model),
null,
null,
initialModel: widget.model,
);

if (_formModel.form.disabled) {
Expand Down Expand Up @@ -246,7 +247,9 @@ class _ArrayNullableOFormBuilderState extends State<ArrayNullableOFormBuilder> {
@override
void didUpdateWidget(covariant ArrayNullableOFormBuilder oldWidget) {
if (widget.model != oldWidget.model) {
_formModel.updateValue(widget.model);
_formModel
..updateValue(widget.model)
..commitInitial(widget.model);
}

super.didUpdateWidget(oldWidget);
Expand Down Expand Up @@ -282,8 +285,12 @@ final _logArrayNullableOForm = Logger.detached('ArrayNullableOForm');

class ArrayNullableOForm
implements FormModel<ArrayNullableO, ArrayNullableOOutput> {
ArrayNullableOForm(this.form, this.path, this._formModel)
: initial = form.rawValue;
ArrayNullableOForm(
this.form,
this.path,
this._formModel, {
ArrayNullableO? initialModel,
}) : _ownInitialModel = initialModel;

static const String emailListControlName = "emailList";

Expand All @@ -304,8 +311,10 @@ class ArrayNullableOForm

final Map<String, bool> _disabled = {};

@override
final Map<String, Object?> initial;
ArrayNullableO? _ownInitialModel;

late Map<String, Object?> _ownInitialRawValue =
ArrayNullableOForm.formElements(_ownInitialModel).rawValue;

String someListControlPath() => pathBuilder(someListControlName);

Expand Down Expand Up @@ -1047,10 +1056,28 @@ class ArrayNullableOForm
bool get hasChanged {
return !const DeepCollectionEquality().equals(
currentForm.rawValue,
initial,
FormModel.sliceByPath(initialRawValue, path),
);
}

@override
Map<String, Object?> get initialRawValue {
return _formModel != null
? _formModel!.initialRawValue
: _ownInitialRawValue;
}

ArrayNullableO? get initialModel {
return _ownInitialModel;
}

void commitInitial([ArrayNullableO? newModel]) {
_ownInitialModel = newModel ?? rawModel;
_ownInitialRawValue = ArrayNullableOForm.formElements(
_ownInitialModel,
).rawValue;
}

@override
FormGroup get currentForm {
return path == null ? form : form.control(path!) as FormGroup;
Expand Down Expand Up @@ -1089,55 +1116,6 @@ class ArrayNullableOForm
emitEvent: emitEvent,
);

@override
void updateInitial(Map<String, Object?>? value, String? path) {
if (_formModel != null) {
_formModel?.updateInitial(currentForm.rawValue, path);
return;
}

if (value == null) return;

if (path == null || path.isEmpty) {
initial.addAll(value);
return;
}

final keys = path.split('.');
Object? current = initial;
for (var i = 0; i < keys.length - 1; i++) {
final key = keys[i];

if (current is List) {
final index = int.tryParse(key);
if (index != null && index >= 0 && index < current.length) {
current = current[index];
continue;
}
}

if (current is Map) {
if (!current.containsKey(key)) {
current[key] = <String, Object?>{};
}
current = current[key];
continue;
}

return;
}

final key = keys.last;
if (current is List) {
final index = int.tryParse(key);
if (index != null && index >= 0 && index < current.length) {
current[index] = value;
}
} else if (current is Map) {
current[key] = value;
}
}

String pathBuilder(String? pathItem) =>
[path, pathItem].whereType<String>().join(".");

Expand Down
88 changes: 33 additions & 55 deletions packages/generator_tests/test/doc/array_nullable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
ArrayNullableForm.formElements(widget.model),
null,
null,
initialModel: widget.model,
);

if (_formModel.form.disabled) {
Expand Down Expand Up @@ -249,7 +250,9 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
@override
void didUpdateWidget(covariant ArrayNullableFormBuilder oldWidget) {
if (widget.model != oldWidget.model) {
_formModel.updateValue(widget.model);
_formModel
..updateValue(widget.model)
..commitInitial(widget.model);
}

super.didUpdateWidget(oldWidget);
Expand Down Expand Up @@ -284,8 +287,12 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
final _logArrayNullableForm = Logger.detached('ArrayNullableForm');

class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
ArrayNullableForm(this.form, this.path, this._formModel)
: initial = form.rawValue;
ArrayNullableForm(
this.form,
this.path,
this._formModel, {
ArrayNullable? initialModel,
}) : _ownInitialModel = initialModel;

static const String emailListControlName = "emailList";

Expand All @@ -308,8 +315,10 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {

final Map<String, bool> _disabled = {};

@override
final Map<String, Object?> initial;
ArrayNullable? _ownInitialModel;

late Map<String, Object?> _ownInitialRawValue =
ArrayNullableForm.formElements(_ownInitialModel).rawValue;

String someListControlPath() => pathBuilder(someListControlName);

Expand Down Expand Up @@ -1134,10 +1143,28 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
bool get hasChanged {
return !const DeepCollectionEquality().equals(
currentForm.rawValue,
initial,
FormModel.sliceByPath(initialRawValue, path),
);
}

@override
Map<String, Object?> get initialRawValue {
return _formModel != null
? _formModel!.initialRawValue
: _ownInitialRawValue;
}

ArrayNullable? get initialModel {
return _ownInitialModel;
}

void commitInitial([ArrayNullable? newModel]) {
_ownInitialModel = newModel ?? rawModel;
_ownInitialRawValue = ArrayNullableForm.formElements(
_ownInitialModel,
).rawValue;
}

@override
FormGroup get currentForm {
return path == null ? form : form.control(path!) as FormGroup;
Expand Down Expand Up @@ -1176,55 +1203,6 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
emitEvent: emitEvent,
);

@override
void updateInitial(Map<String, Object?>? value, String? path) {
if (_formModel != null) {
_formModel?.updateInitial(currentForm.rawValue, path);
return;
}

if (value == null) return;

if (path == null || path.isEmpty) {
initial.addAll(value);
return;
}

final keys = path.split('.');
Object? current = initial;
for (var i = 0; i < keys.length - 1; i++) {
final key = keys[i];

if (current is List) {
final index = int.tryParse(key);
if (index != null && index >= 0 && index < current.length) {
current = current[index];
continue;
}
}

if (current is Map) {
if (!current.containsKey(key)) {
current[key] = <String, Object?>{};
}
current = current[key];
continue;
}

return;
}

final key = keys.last;
if (current is List) {
final index = int.tryParse(key);
if (index != null && index >= 0 && index < current.length) {
current[index] = value;
}
} else if (current is Map) {
current[key] = value;
}
}

String pathBuilder(String? pathItem) =>
[path, pathItem].whereType<String>().join(".");

Expand Down
Loading
Loading