Skip to content

Commit

Permalink
[bump] version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
schultek committed May 8, 2023
1 parent b603072 commit 190fe10
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 58 deletions.
124 changes: 101 additions & 23 deletions packages/dart_mappable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,118 @@
# 3.0.0-dev.5
# 3.0.0

- Make delta copy-with null aware.
- Add `renameMethods` to build options.
- **Breaking**: Generated mappers no longer have a `.container` property. This was removed in favor
of the new `MapperContainer.globals` container.

# 3.0.0-dev.4
```dart
// Instead of this:
var value = MyClassMapper.container.fromValue(...);
// Do this:
var value = MapperContainer.globals.fromValue(...);
```

- Chore: Improved docs and tests.
- Copy-With now supports classes that implement multiple interfaces.
- Added support for serializing fields that are not part of the constructor
when annotated with `@MappableField()`.
Mapper initialization and usage is now simplified to the following:

# 3.0.0-dev.3
1. When used explicitly (e.g. through `MyClassMapper.fromMap` or `myClass.toMap()`) no additional
initialization is needed.
2. When used implicitly (through a generic type e.g. `MapperContainer.globals.fromMap<MyClass>()`) the
mapper needs to be initialized once before being used with `MyClassMapper.ensureInitialized()`.

- Fixed bug with null in encoding hook.

# 3.0.0-dev.2
- **Breaking**: Changed internal mapper implementation which causes any custom mapper to break.
- Removed `MapperElementBase` class.
- Added `MappingContext` being passed to mapper methods.

- Performance improvements & bug fixes.
*See docs on how to use custom mappers in v3.*

# 3.0.0-dev.1

- Bug fixes.
- **Breaking**: Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`.

# 3.0.0-dev.0
Instead of generating a new container, v3 generates an initialization function for all mappers. Use it early on in your
application:

- Simplified internal mapper implementation and removed `MapperElementBase` class.
- Added `MappingContext` being passed to mapper methods.
```dart
@MappableLib(generateInitializerForScope: InitializerScope.package)
library main;
import 'main.init.dart';
void main() {
initializeMappers();
...
}
```


- **Breaking**: Improved support and features for `.copyWith`.

- Copy-With now supports classes that implement multiple interfaces.
- Renamed `.copyWith.apply()` method to `.copyWith.$update()`.
- Added `.copyWith.$merge()` and `.copyWith.$delta()`.

You can now use `.copyWith` with either an existing instance using `.$merge` or a map of values using `.$delta`.

```dart
@MappableClass()
class A with AMappable {
A(this.a, this.b);
int? a;
int? b;
}
void main() {
var a = A(1, null);
var c = a.copyWith.$merge(A(null, 2));
assert(c == A(1, 2));
var d = a.copyWith.$delta({'b': 2});
assert(d == A(1, 2));
}
```


- **Breaking**: Removed `CheckTypesHook` in favor of discriminator functions.

You can now use a custom predicate function as the `discriminatorValue` of a class. This function can check
whether the encoded value should be decoded to this subclass and return a boolean.

```dart
@MappableClass()
abstract class A with AMappable {
A();
}
@MappableClass(discriminatorValue: B.checkType)
class B extends A with BMappable {
B();
/// checks if [value] should be decoded to [B]
static bool checkType(value) {
return value is Map && value['isB'] == true;
}
}
@MappableClass(discriminatorValue: C.checkType)
class C extends A with CMappable {
C();
/// checks if [value] should be decoded to [C]
static bool checkType(value) {
return value is Map && value['isWhat'] == 'C';
}
}
```


- Added support for serializing fields that are not part of the constructor
when annotated with `@MappableField()`.
- Added `EncodingOptions` to `toValue` method.
- Added support for third-party models by using annotated `typedef`s.
- Removed `<MyClass>Mapper.container` in favor of `MapperContainer.globals`.
- Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`.
- Renamed `.copyWith.apply()` method to `.copyWith.$update()`.
- Removed `CheckTypesHook` in favor of discriminator functions.
- Added `.copyWith.$merge()` and `.copyWith.$delta()`.
- Added `renameMethods` to build options.
- Improved performance of generated encoding and decoding methods.

For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71).
For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71).

# 2.0.3

Expand Down
5 changes: 2 additions & 3 deletions packages/dart_mappable/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: true
language:
strict-casts: true

linter:
rules:
Expand Down
4 changes: 2 additions & 2 deletions packages/dart_mappable/doc/polymorphism.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ two problems arise:
- When deserializing, we need to make sure that the correct subclass is chosen and instantiated, and
- when serializing, we need to make sure that the subclass information isn't lost.

To solve these, we need to add a **discriminator property**, that keeps track of the specific *(sub)*-type of the `pet`.
To solve these, we add a **discriminator property**, that keeps track of the specific *(sub)*-type of the `pet`.

By default no discriminator is applied, but you can change this by setting the `discriminatorKey` annotation property (or globally in the build configuration).
By default, no discriminator is applied, but you can change this by setting the `discriminatorKey` annotation property (or globally in the build configuration).

The value of this property will default to the name of the class, but you can change this as well with the `discriminatorValue` annotation property.

Expand Down
6 changes: 3 additions & 3 deletions packages/dart_mappable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: dart_mappable
description: Improved json serialization and data classes with full support for generics, inheritance, customization and more.
version: 3.0.0-dev.5
version: 3.0.0
repository: https://github.com/schultek/dart_mappable
issue_tracker: https://github.com/schultek/dart_mappable/issues
documentation: https://pub.dev/documentation/dart_mappable/latest/topics/Introduction-topic.html
funding:
- https://github.com/sponsors/schultek

environment:
sdk: '>=2.17.0 <3.0.0'
sdk: '>=2.17.0 <4.0.0'

dependencies:
collection: ^1.15.0
Expand All @@ -17,6 +17,6 @@ dependencies:

dev_dependencies:
build_runner: ^2.2.0
dart_mappable_builder: ^3.0.0-dev.5
dart_mappable_builder: ^3.0.0
lints: '>=1.0.0 <3.0.0'
test: ^1.20.1
124 changes: 103 additions & 21 deletions packages/dart_mappable_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,118 @@
# 3.0.0-dev.5
# 3.0.0

- Make delta copy-with null aware.
- Add `renameMethods` to build options.
- **Breaking**: Generated mappers no longer have a `.container` property. This was removed in favor
of the new `MapperContainer.globals` container.

# 3.0.0-dev.4
```dart
// Instead of this:
var value = MyClassMapper.container.fromValue(...);
// Do this:
var value = MapperContainer.globals.fromValue(...);
```

- Chore: Improved docs and tests.
- Copy-With now supports classes that implement multiple interfaces.
- Added support for serializing fields that are not part of the constructor
when annotated with `@MappableField()`.
Mapper initialization and usage is now simplified to the following:

1. When used explicitly (e.g. through `MyClassMapper.fromMap` or `myClass.toMap()`) no additional
initialization is needed.
2. When used implicitly (through a generic type e.g. `MapperContainer.globals.fromMap<MyClass>()`) the
mapper needs to be initialized once before being used with `MyClassMapper.ensureInitialized()`.


- **Breaking**: Changed internal mapper implementation which causes any custom mapper to break.
- Removed `MapperElementBase` class.
- Added `MappingContext` being passed to mapper methods.

*See docs on how to use custom mappers in v3.*

# 3.0.0-dev.2

- Performance improvements & bug fixes
- **Breaking**: Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`.

# 3.0.0-dev.1
Instead of generating a new container, v3 generates an initialization function for all mappers. Use it early on in your
application:

- Bug fixes
```dart
@MappableLib(generateInitializerForScope: InitializerScope.package)
library main;
import 'main.init.dart';
void main() {
initializeMappers();
...
}
```

# 3.0.0-dev.0

- Simplified internal mapper implementation and removed `MapperElementBase` class.
- Added `MappingContext` being passed to mapper methods.
- **Breaking**: Improved support and features for `.copyWith`.

- Copy-With now supports classes that implement multiple interfaces.
- Renamed `.copyWith.apply()` method to `.copyWith.$update()`.
- Added `.copyWith.$merge()` and `.copyWith.$delta()`.

You can now use `.copyWith` with either an existing instance using `.$merge` or a map of values using `.$delta`.

```dart
@MappableClass()
class A with AMappable {
A(this.a, this.b);
int? a;
int? b;
}
void main() {
var a = A(1, null);
var c = a.copyWith.$merge(A(null, 2));
assert(c == A(1, 2));
var d = a.copyWith.$delta({'b': 2});
assert(d == A(1, 2));
}
```


- **Breaking**: Removed `CheckTypesHook` in favor of discriminator functions.

You can now use a custom predicate function as the `discriminatorValue` of a class. This function can check
whether the encoded value should be decoded to this subclass and return a boolean.

```dart
@MappableClass()
abstract class A with AMappable {
A();
}
@MappableClass(discriminatorValue: B.checkType)
class B extends A with BMappable {
B();
/// checks if [value] should be decoded to [B]
static bool checkType(value) {
return value is Map && value['isB'] == true;
}
}
@MappableClass(discriminatorValue: C.checkType)
class C extends A with CMappable {
C();
/// checks if [value] should be decoded to [C]
static bool checkType(value) {
return value is Map && value['isWhat'] == 'C';
}
}
```


- Added support for serializing fields that are not part of the constructor
when annotated with `@MappableField()`.
- Added `EncodingOptions` to `toValue` method.
- Added support for third-party models by using annotated `typedef`s.
- Removed `<MyClass>Mapper.container` in favor of `MapperContainer.globals`.
- Removed `@MappableLib.createCombinedContainer` in favor of `@MappableLib.generateInitializerForScope`.
- Renamed `.copyWith.apply()` method to `.copyWith.$update()`.
- Removed `CheckTypesHook` in favor of discriminator functions.
- Added `.copyWith.$merge()` and `.copyWith.$delta()`.
- Added `renameMethods` to build options.
- Improved performance of generated encoding and decoding methods.

For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71).
For a detailed migration guide, see [this issue](https://github.com/schultek/dart_mappable/issues/71).

# 2.0.2

Expand Down
5 changes: 2 additions & 3 deletions packages/dart_mappable_builder/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: true
language:
strict-casts: true

linter:
rules:
Expand Down
6 changes: 3 additions & 3 deletions packages/dart_mappable_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: dart_mappable_builder
description: Improved json serialization and data classes with full support for generics, inheritance, customization and more.
version: 3.0.0-dev.5
version: 3.0.0
repository: https://github.com/schultek/dart_mappable
issue_tracker: https://github.com/schultek/dart_mappable/issues
funding:
- https://github.com/sponsors/schultek

environment:
sdk: '>=2.17.0 <3.0.0'
sdk: '>=2.17.0 <4.0.0'

dependencies:
analyzer: ^5.2.0
ansicolor: ^2.0.1
build: ^2.0.0
collection: ^1.15.0
dart_mappable: ^3.0.0-dev.5
dart_mappable: ^3.0.0
dart_style: ^2.2.4
glob: ^2.1.0
path: ^1.8.0
Expand Down

0 comments on commit 190fe10

Please sign in to comment.