Skip to content

Commit

Permalink
first iteration of toOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Jun 1, 2024
1 parent f02d042 commit 20011bb
Show file tree
Hide file tree
Showing 54 changed files with 393 additions and 138 deletions.
4 changes: 4 additions & 0 deletions packages/reactive_forms_annotations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [6.0.0-beta.0]

* output

## [5.0.0]

* rf17
Expand Down
6 changes: 3 additions & 3 deletions packages/reactive_forms_annotations/lib/src/form_model.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:reactive_forms/reactive_forms.dart';

abstract class FormModel<TModel> {
abstract class FormModel<TModel, TModelOutput> {
FormModel({
required this.form,
});

final FormGroup form;

TModel get model;
TModelOutput get model;

void submit({
required void Function(TModel model) onValid,
required void Function(TModelOutput model) onValid,
void Function()? onNotValid,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/reactive_forms_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repository: https://github.com/artflutter/reactive_forms_generator
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 5.0.0
version: 6.0.0-beta.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/reactive_forms_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [6.0.0-beta.0]

* output

## [5.0.1]

* error type fix
Expand Down
1 change: 1 addition & 0 deletions packages/reactive_forms_generator/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.ipr
*.iws
.idea/
linux

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _UrlFormBuilderState extends State<UrlFormBuilder> {
}
}

class UrlForm implements FormModel<Url> {
class UrlForm implements FormModel<Url, Url> {
UrlForm(
this.form,
this.path,
Expand Down Expand Up @@ -472,7 +472,7 @@ class UrlForm implements FormModel<Url> {
disabled: false);
}

class UrlEntityForm implements FormModel<UrlEntity> {
class UrlEntityForm implements FormModel<UrlEntity, UrlEntity> {
UrlEntityForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _AnnotatelessFormBuilderState extends State<AnnotatelessFormBuilder> {
}
}

class AnnotatelessForm implements FormModel<Annotateless> {
class AnnotatelessForm implements FormModel<Annotateless, Annotateless> {
AnnotatelessForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
}
}

class ArrayNullableForm implements FormModel<ArrayNullable> {
class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
ArrayNullableForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
}
}

class DeliveryListForm implements FormModel<DeliveryList> {
class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
DeliveryListForm(
this.form,
this.path,
Expand Down Expand Up @@ -702,7 +702,7 @@ class DeliveryListForm implements FormModel<DeliveryList> {
disabled: false);
}

class DeliveryPointForm implements FormModel<DeliveryPoint> {
class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
DeliveryPointForm(
this.form,
this.path,
Expand Down Expand Up @@ -982,7 +982,7 @@ class DeliveryPointForm implements FormModel<DeliveryPoint> {
disabled: false);
}

class AddressForm implements FormModel<Address> {
class AddressForm implements FormModel<Address, Address> {
AddressForm(
this.form,
this.path,
Expand Down Expand Up @@ -1290,7 +1290,7 @@ class AddressForm implements FormModel<Address> {
disabled: false);
}

class ClientForm implements FormModel<Client> {
class ClientForm implements FormModel<Client, Client> {
ClientForm(
this.form,
this.path,
Expand Down Expand Up @@ -1984,7 +1984,8 @@ class _StandaloneDeliveryPointFormBuilderState
}
}

class StandaloneDeliveryPointForm implements FormModel<DeliveryPoint> {
class StandaloneDeliveryPointForm
implements FormModel<DeliveryPoint, DeliveryPoint> {
StandaloneDeliveryPointForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _FreezedClassFormBuilderState extends State<FreezedClassFormBuilder> {
}
}

class FreezedClassForm implements FormModel<FreezedClass> {
class FreezedClassForm implements FormModel<FreezedClass, FreezedClass> {
FreezedClassForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _TestFormBuilderState extends State<TestFormBuilder> {
}
}

class TestForm implements FormModel<Test> {
class TestForm implements FormModel<Test, Test> {
TestForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _TagsFormBuilderState<T> extends State<TagsFormBuilder<T>> {
}
}

class TagsForm<T> implements FormModel<Tags<T>> {
class TagsForm<T> implements FormModel<Tags<T>, Tags<T>> {
TagsForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class _StatusListFormBuilderState<T extends Enum>
}
}

class StatusListForm<T extends Enum> implements FormModel<StatusList<T>> {
class StatusListForm<T extends Enum>
implements FormModel<StatusList<T>, StatusList<T>> {
StatusListForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _GroupFormBuilderState extends State<GroupFormBuilder> {
}
}

class GroupForm implements FormModel<Group> {
class GroupForm implements FormModel<Group, Group> {
GroupForm(
this.form,
this.path,
Expand Down Expand Up @@ -693,7 +693,7 @@ class GroupForm implements FormModel<Group> {
disabled: false);
}

class PersonalForm implements FormModel<Personal> {
class PersonalForm implements FormModel<Personal, Personal> {
PersonalForm(
this.form,
this.path,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ class PersonalForm implements FormModel<Personal> {
disabled: false);
}

class PhoneForm implements FormModel<Phone> {
class PhoneForm implements FormModel<Phone, Phone> {
PhoneForm(
this.form,
this.path,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ class PhoneForm implements FormModel<Phone> {
disabled: false);
}

class AddressForm implements FormModel<Address> {
class AddressForm implements FormModel<Address, Address> {
AddressForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _LoginFormBuilderState extends State<LoginFormBuilder> {
}
}

class LoginForm implements FormModel<Login> {
class LoginForm implements FormModel<Login, Login> {
LoginForm(
this.form,
this.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class LoginOFormBuilder extends StatefulWidget {
this.initState,
}) : super(key: key);

final LoginOOutput? model;
final LoginO? model;

final Widget? child;

Expand Down Expand Up @@ -191,7 +191,7 @@ class LoginOOutput extends Equatable {
List<Object?> get props => [email, password];
}

class LoginOForm implements FormModel<LoginOOutput> {
class LoginOForm implements FormModel<LoginO, LoginOOutput> {
LoginOForm(
this.form,
this.path,
Expand All @@ -211,9 +211,9 @@ class LoginOForm implements FormModel<LoginOOutput> {

String passwordControlPath() => pathBuilder(passwordControlName);

String? get _emailValue => emailControl?.value;
String get _emailValue => emailControl.value as String;

String? get _passwordValue => passwordControl?.value;
String get _passwordValue => passwordControl.value as String;

bool get containsEmail {
try {
Expand All @@ -233,9 +233,9 @@ class LoginOForm implements FormModel<LoginOOutput> {
}
}

Map<String, Object>? get emailErrors => emailControl?.errors;
Map<String, Object>? get emailErrors => emailControl.errors;

Map<String, Object>? get passwordErrors => passwordControl?.errors;
Map<String, Object>? get passwordErrors => passwordControl.errors;

void get emailFocus => form.focus(emailControlPath());

Expand Down Expand Up @@ -298,7 +298,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool updateParent = true,
bool emitEvent = true,
}) {
emailControl?.updateValue(value,
emailControl.updateValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}

Expand All @@ -307,7 +307,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool updateParent = true,
bool emitEvent = true,
}) {
passwordControl?.updateValue(value,
passwordControl.updateValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}

Expand All @@ -316,7 +316,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool updateParent = true,
bool emitEvent = true,
}) {
emailControl?.patchValue(value,
emailControl.patchValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}

Expand All @@ -325,7 +325,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool updateParent = true,
bool emitEvent = true,
}) {
passwordControl?.patchValue(value,
passwordControl.patchValue(value,
updateParent: updateParent, emitEvent: emitEvent);
}

Expand All @@ -336,7 +336,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool removeFocus = false,
bool? disabled,
}) =>
emailControl?.reset(
emailControl.reset(
value: value, updateParent: updateParent, emitEvent: emitEvent);

void passwordValueReset(
Expand All @@ -346,29 +346,27 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool removeFocus = false,
bool? disabled,
}) =>
passwordControl?.reset(
passwordControl.reset(
value: value, updateParent: updateParent, emitEvent: emitEvent);

FormControl<String>? get emailControl => containsEmail
? form.control(emailControlPath()) as FormControl<String>?
: null;
FormControl<String> get emailControl =>
form.control(emailControlPath()) as FormControl<String>;

FormControl<String>? get passwordControl => containsPassword
? form.control(passwordControlPath()) as FormControl<String>?
: null;
FormControl<String> get passwordControl =>
form.control(passwordControlPath()) as FormControl<String>;

void emailSetDisabled(
bool disabled, {
bool updateParent = true,
bool emitEvent = true,
}) {
if (disabled) {
emailControl?.markAsDisabled(
emailControl.markAsDisabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
} else {
emailControl?.markAsEnabled(
emailControl.markAsEnabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
Expand All @@ -381,12 +379,12 @@ class LoginOForm implements FormModel<LoginOOutput> {
bool emitEvent = true,
}) {
if (disabled) {
passwordControl?.markAsDisabled(
passwordControl.markAsDisabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
} else {
passwordControl?.markAsEnabled(
passwordControl.markAsEnabled(
updateParent: updateParent,
emitEvent: emitEvent,
);
Expand Down Expand Up @@ -456,7 +454,7 @@ class LoginOForm implements FormModel<LoginOOutput> {

@override
void updateValue(
LoginOOutput? value, {
LoginO? value, {
bool updateParent = true,
bool emitEvent = true,
}) =>
Expand All @@ -465,7 +463,7 @@ class LoginOForm implements FormModel<LoginOOutput> {

@override
void reset({
LoginOOutput? value,
LoginO? value,
bool updateParent = true,
bool emitEvent = true,
}) =>
Expand All @@ -477,7 +475,7 @@ class LoginOForm implements FormModel<LoginOOutput> {
String pathBuilder(String? pathItem) =>
[path, pathItem].whereType<String>().join(".");

static FormGroup formElements(LoginOOutput? loginO) => FormGroup({
static FormGroup formElements(LoginO? loginO) => FormGroup({
emailControlName: FormControl<String>(
value: loginO?.email,
validators: [RequiredValidator(), RequiredValidator()],
Expand Down
Loading

0 comments on commit 20011bb

Please sign in to comment.