Skip to content

Commit 0a159f5

Browse files
committed
Merge branch 'master' into pub
2 parents ab12002 + e4ec036 commit 0a159f5

File tree

104 files changed

+809
-1552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+809
-1552
lines changed

.tools/all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
.tools/init || exit 1
77
.tools/fix || exit 1
88
.tools/format || exit 1
9-
.tools/analyze || exit 1
109
.tools/build || exit 1
1110
.tools/cpex || exit 1
1211
.tools/test || exit 1
1312
.tools/coverage || exit 1
1413
.tools/example || exit 1
14+
.tools/analyze || exit 1
1515

1616
git add .
1717
git status

.tools/all.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ call .tools\cprm || exit 1
66
call .tools\init || exit 1
77
call .tools\fix || exit 1
88
call .tools\format || exit 1
9-
call .tools\analyze || exit 1
109
call .tools\build || exit 1
1110
call .tools\cpex || exit 1
1211
call .tools\test || exit 1
1312
call .tools\coverage || exit 1
1413
call .tools\example || exit 1
14+
call .tools\analyze || exit 1
1515

1616
git add .
1717
git status

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
## 1.0.0
1+
## 1.2.0
22

3-
- Initial version
3+
- Using factory instead of static methods
4+
- Disabled copy method generation
45

56
## 1.1.0
67

78
- Decoupled super_enum APIs from dart_sealed
9+
10+
## 1.0.0
11+
12+
- Initial version

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Generate sealed class hierarchy for Dart and Flutter, For null-safe and legacy p
1212

1313
## Features
1414

15-
* Generate sealed class with abstract super type and data sub classes.
15+
* Generate sealed class with abstract super type and data sub-classes.
1616
* Static factory methods. for example `Result.success(data: 0)`.
1717
* Cast methods. for example `a.asSuccess()`, `a.isSuccess()` or `a.asSuccessOrNull()`.
1818
* Three types of equality and hashCode generation : data (like kotlin data classes), identity and distinct.
@@ -53,7 +53,7 @@ part 'weather.sealed.dart';
5353
Add `@Sealed` annotation, and an abstract private class as a manifest for generated code.
5454

5555
You can choose between three types of equality using `@WithEquality(...)` annotation. Default equality is `data` if not
56-
specified. This will become default equality for all sub classes. You can change equality of each sub class by using
56+
specified. This will become default equality for all sub-classes. You can change equality of each sub-class by using
5757
this annotation on individual methods.
5858

5959
Equality types:
@@ -92,14 +92,14 @@ abstract class _Weather {
9292
```
9393

9494
An abstract super class is generated with name equal to name of manifest class without the underline (here `Weather`).
95-
Each method will become a sub class. There should be at least one method. Sub class names are based on method name
95+
Each method will become a sub-class. There should be at least one method. sub-class names are based on method name
9696
prefixed with super class name (for example `WeatherSunny`). Naming process can be tailored with use of `@WithPrefix`
97-
and `@WithName` annotations. Each method argument will become a field in corresponding sub class. Field names are equal
97+
and `@WithName` annotations. Each method argument will become a field in corresponding sub-class. Field names are equal
9898
to argument names and field types are equal to argument types or dynamic if not specified. Argument types can be
9999
overridden using `@WithType` annotation for example when type information is not available at build time. Note that you
100100
can have nullable and non-nullable fields. In legacy projects all fields are considered nullable.
101101

102-
To change prefix of sub class names which by default is top class name, you can use `@WithPrefix` annotation. for
102+
To change prefix of sub-class names which by default is top class name, you can use `@WithPrefix` annotation. for
103103
example:
104104

105105
```dart
@@ -111,9 +111,9 @@ abstract class _Weather {
111111
```
112112

113113
Now `sunny` will be named `HelloSunny` instead of the default `WeatherSunny`. You can use `@WithPrefix('')` to remove
114-
all prefix from sub class names.
114+
all prefix from sub-class names.
115115

116-
To change sub class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
116+
To change sub-class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
117117
example:
118118

119119
```dart
@@ -124,11 +124,11 @@ abstract class _Weather {
124124
}
125125
```
126126

127-
Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is use full if you want not to use prefix
127+
Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is useful if you want not to use prefix
128128
for some items.
129129

130-
Almost all methods on sealed classes use short names extracted from manifest method names. Full sub class names are not
131-
used. It is recommended not to use sub classes directly. There are factory methods for each item on super class.
130+
Almost all methods on sealed classes use short names extracted from manifest method names. Full sub-class names are not
131+
used. It is recommended not to use sub-classes directly. There are factory methods for each item on super class.
132132

133133
Then run the following command to generate code for you.
134134

@@ -140,8 +140,7 @@ The generated code will look like: (the following code is summarised)
140140

141141
```dart
142142
abstract class Weather {
143-
static WeatherRainy rainy({required int rain}) =>
144-
WeatherRainy(rain: rain);
143+
factory Weather.rainy({required int rain}) = WeatherRainy;
145144
146145
bool isRainy() => this is WeatherRainy;
147146
@@ -213,9 +212,6 @@ class WeatherRainy extends Weather with EquatableMixin {
213212
214213
final int rain;
215214
216-
WeatherRainy copy({int? rain}) =>
217-
WeatherRainy(rain: rain ?? this.rain);
218-
219215
@override
220216
String toString() => 'Weather.rainy(rain: $rain)';
221217
@@ -231,7 +227,7 @@ class WeatherWindy extends Weather {
231227
Notes:
232228

233229
- Always use exact match method that you need, for example do not use `whenOrNull` instead of `whenPartial`.
234-
- Prefer using factories in super class instead of sub class constructors.
230+
- Prefer using factories in super class instead of sub-class constructors.
235231
- Minimize usage of cast methods, most of the time they can be replaced with a match method.
236232

237233
## Generic Usage
@@ -276,7 +272,7 @@ abstract class _Result<D extends num, E extends Object> {
276272
## Wrapping and Inheritance
277273

278274
There are times when you are using a sealed type only to wrap some fields and then unwrap it by using match functions in
279-
for example your blocs. In these situations it is better for the sealed sub class not to appear explicitly.
275+
for example your blocs. In these situations it is better for the sealed sub-class not to appear explicitly.
280276

281277
for example suppose the following manifest:
282278

@@ -332,8 +328,8 @@ Object doTest(State s) {
332328
}
333329
```
334330

335-
As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub classes.
336-
If you want wrapping only for some of your sub classes apply them to methods. for example:
331+
As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub-classes.
332+
If you want wrapping only for some of your sub-classes apply them to methods. for example:
337333

338334
```dart
339335
@Sealed()
@@ -350,7 +346,7 @@ abstract class State {
350346

351347
In previous example `data` will not be automatically unwrapped.
352348

353-
Also, when making a sealed sub class wrapped, its constructor and the corresponding factory in sealed super class will
349+
Also, when making a sealed sub-class wrapped, its constructor and the corresponding factory in sealed super class will
354350
be using positional arguments instead of named arguments. For example for `data`:
355351

356352
```dart
@@ -408,7 +404,7 @@ For more information check `super_enum` documentation:
408404

409405
### migrating from super_enum
410406

411-
If you were using super_enum and now you want to change your dependency to dart_sealed:
407+
If you were using super_enum, and now you want to change your dependency to dart_sealed:
412408

413409
* Change dependency of `super_enum` with `super_enum_sealed_annotations`.
414410
* Add dependency to `sealed_annotations`.

sealed_annotations/CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
## 1.0.0
1+
## 1.2.0
22

3-
- Initial version
3+
- Using factory instead of static methods
4+
- Disabled copy method generation
45

56
## 1.1.0
67

78
- Decoupled super_enum APIs from dart_sealed
9+
10+
## 1.0.0
11+
12+
- Initial version

sealed_annotations/README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Generate sealed class hierarchy for Dart and Flutter, For null-safe and legacy p
1212

1313
## Features
1414

15-
* Generate sealed class with abstract super type and data sub classes.
15+
* Generate sealed class with abstract super type and data sub-classes.
1616
* Static factory methods. for example `Result.success(data: 0)`.
1717
* Cast methods. for example `a.asSuccess()`, `a.isSuccess()` or `a.asSuccessOrNull()`.
1818
* Three types of equality and hashCode generation : data (like kotlin data classes), identity and distinct.
@@ -53,7 +53,7 @@ part 'weather.sealed.dart';
5353
Add `@Sealed` annotation, and an abstract private class as a manifest for generated code.
5454

5555
You can choose between three types of equality using `@WithEquality(...)` annotation. Default equality is `data` if not
56-
specified. This will become default equality for all sub classes. You can change equality of each sub class by using
56+
specified. This will become default equality for all sub-classes. You can change equality of each sub-class by using
5757
this annotation on individual methods.
5858

5959
Equality types:
@@ -92,14 +92,14 @@ abstract class _Weather {
9292
```
9393

9494
An abstract super class is generated with name equal to name of manifest class without the underline (here `Weather`).
95-
Each method will become a sub class. There should be at least one method. Sub class names are based on method name
95+
Each method will become a sub-class. There should be at least one method. sub-class names are based on method name
9696
prefixed with super class name (for example `WeatherSunny`). Naming process can be tailored with use of `@WithPrefix`
97-
and `@WithName` annotations. Each method argument will become a field in corresponding sub class. Field names are equal
97+
and `@WithName` annotations. Each method argument will become a field in corresponding sub-class. Field names are equal
9898
to argument names and field types are equal to argument types or dynamic if not specified. Argument types can be
9999
overridden using `@WithType` annotation for example when type information is not available at build time. Note that you
100100
can have nullable and non-nullable fields. In legacy projects all fields are considered nullable.
101101

102-
To change prefix of sub class names which by default is top class name, you can use `@WithPrefix` annotation. for
102+
To change prefix of sub-class names which by default is top class name, you can use `@WithPrefix` annotation. for
103103
example:
104104

105105
```dart
@@ -111,9 +111,9 @@ abstract class _Weather {
111111
```
112112

113113
Now `sunny` will be named `HelloSunny` instead of the default `WeatherSunny`. You can use `@WithPrefix('')` to remove
114-
all prefix from sub class names.
114+
all prefix from sub-class names.
115115

116-
To change sub class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
116+
To change sub-class names directly you can use `@WithName` annotation. It will override `WithPrefix` if specified. for
117117
example:
118118

119119
```dart
@@ -124,11 +124,11 @@ abstract class _Weather {
124124
}
125125
```
126126

127-
Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is use full if you want not to use prefix
127+
Now `sunny` will be named `Hello` instead of the default `WeatherSunny`. This is useful if you want not to use prefix
128128
for some items.
129129

130-
Almost all methods on sealed classes use short names extracted from manifest method names. Full sub class names are not
131-
used. It is recommended not to use sub classes directly. There are factory methods for each item on super class.
130+
Almost all methods on sealed classes use short names extracted from manifest method names. Full sub-class names are not
131+
used. It is recommended not to use sub-classes directly. There are factory methods for each item on super class.
132132

133133
Then run the following command to generate code for you.
134134

@@ -140,8 +140,7 @@ The generated code will look like: (the following code is summarised)
140140

141141
```dart
142142
abstract class Weather {
143-
static WeatherRainy rainy({required int rain}) =>
144-
WeatherRainy(rain: rain);
143+
factory Weather.rainy({required int rain}) = WeatherRainy;
145144
146145
bool isRainy() => this is WeatherRainy;
147146
@@ -213,9 +212,6 @@ class WeatherRainy extends Weather with EquatableMixin {
213212
214213
final int rain;
215214
216-
WeatherRainy copy({int? rain}) =>
217-
WeatherRainy(rain: rain ?? this.rain);
218-
219215
@override
220216
String toString() => 'Weather.rainy(rain: $rain)';
221217
@@ -231,7 +227,7 @@ class WeatherWindy extends Weather {
231227
Notes:
232228

233229
- Always use exact match method that you need, for example do not use `whenOrNull` instead of `whenPartial`.
234-
- Prefer using factories in super class instead of sub class constructors.
230+
- Prefer using factories in super class instead of sub-class constructors.
235231
- Minimize usage of cast methods, most of the time they can be replaced with a match method.
236232

237233
## Generic Usage
@@ -276,7 +272,7 @@ abstract class _Result<D extends num, E extends Object> {
276272
## Wrapping and Inheritance
277273

278274
There are times when you are using a sealed type only to wrap some fields and then unwrap it by using match functions in
279-
for example your blocs. In these situations it is better for the sealed sub class not to appear explicitly.
275+
for example your blocs. In these situations it is better for the sealed sub-class not to appear explicitly.
280276

281277
for example suppose the following manifest:
282278

@@ -332,8 +328,8 @@ Object doTest(State s) {
332328
}
333329
```
334330

335-
As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub classes.
336-
If you want wrapping only for some of your sub classes apply them to methods. for example:
331+
As you see it automatically unwraps values for you. If you add `@WithWrap()` on class it will apply to all sub-classes.
332+
If you want wrapping only for some of your sub-classes apply them to methods. for example:
337333

338334
```dart
339335
@Sealed()
@@ -350,7 +346,7 @@ abstract class State {
350346

351347
In previous example `data` will not be automatically unwrapped.
352348

353-
Also, when making a sealed sub class wrapped, its constructor and the corresponding factory in sealed super class will
349+
Also, when making a sealed sub-class wrapped, its constructor and the corresponding factory in sealed super class will
354350
be using positional arguments instead of named arguments. For example for `data`:
355351

356352
```dart
@@ -408,7 +404,7 @@ For more information check `super_enum` documentation:
408404

409405
### migrating from super_enum
410406

411-
If you were using super_enum and now you want to change your dependency to dart_sealed:
407+
If you were using super_enum, and now you want to change your dependency to dart_sealed:
412408

413409
* Change dependency of `super_enum` with `super_enum_sealed_annotations`.
414410
* Add dependency to `sealed_annotations`.

0 commit comments

Comments
 (0)