Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions mobx_codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.7.5
- **FIX**: useDeepEquality is not being correctly passed to the generated code.

## 2.7.4
- Drop build_resolvers as a dependency, which enables support for build_runner 2.8.0

Expand Down
6 changes: 6 additions & 0 deletions mobx_codegen/lib/src/store_class_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class StoreClassVisitor extends SimpleElementVisitor2 {
isReadOnly: _isObservableReadOnly(element),
isLate: element.isLate,
equals: _getEquals(element),
useDeepEquality: _getUseDeepEquality(element),
);

_storeTemplate.observables.add(template);
Expand All @@ -129,6 +130,11 @@ class StoreClassVisitor extends SimpleElementVisitor2 {
?.getField('equals')
?.toFunctionValue2();

bool? _getUseDeepEquality(FieldElement2 element) => _observableChecker
.firstAnnotationOfExact(element)
?.getField('useDeepEquality')
?.toBoolValue();

bool _fieldIsNotValid(FieldElement2 element) => _any([
errors.staticObservables.addIf(element.isStatic, element.name3!),
errors.finalObservables.addIf(element.isFinal, element.name3!),
Expand Down
2 changes: 1 addition & 1 deletion mobx_codegen/lib/version.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!!

/// The current version as per `pubspec.yaml`.
const version = '2.7.4';
const version = '2.7.5';
10 changes: 5 additions & 5 deletions mobx_codegen/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mobx_codegen
description: Code generator for MobX that adds support for annotating your code with @observable, @computed, @action and also creating Store classes.
version: 2.7.4
version: 2.7.5

repository: https://github.com/mobxjs/mobx.dart
issue_tracker: https://github.com/mobxjs/mobx.dart/issues
Expand All @@ -11,15 +11,15 @@ topics:
- codegen

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

dependencies:
analyzer: '>=7.4.0 < 9.0.0'
build: '>=3.0.0 < 5.0.0'
analyzer: ">=7.4.0 < 9.0.0"
build: ">=3.0.0 < 5.0.0"
meta: ^1.3.0
mobx: ^2.5.0
path: ^1.8.0
source_gen: '>=3.0.0 < 5.0.0'
source_gen: ">=3.0.0 < 5.0.0"

dev_dependencies:
build_runner: ^2.6.0
Expand Down
41 changes: 41 additions & 0 deletions mobx_codegen/test/store_class_visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,46 @@ void main() {
true,
);
});

test('useDeepEquality is included in generated setter when set to true',
() {
final store = StoreTemplateFake()..parentTypeName = 'TestStore';
final template = ObservableTemplate(
storeTemplate: store,
type: 'List<int>',
name: 'items',
atomName: '_itemsAtom',
useDeepEquality: true,
);
final output = template.toString();
expect(output, contains('useDeepEquality: true'));
});

test('useDeepEquality is included in generated setter when set to false',
() {
final store = StoreTemplateFake()..parentTypeName = 'TestStore';
final template = ObservableTemplate(
storeTemplate: store,
type: 'List<int>',
name: 'items',
atomName: '_itemsAtom',
useDeepEquality: false,
);
final output = template.toString();
expect(output, contains('useDeepEquality: false'));
});

test('useDeepEquality is not included in generated setter when null', () {
final store = StoreTemplateFake()..parentTypeName = 'TestStore';
final template = ObservableTemplate(
storeTemplate: store,
type: 'List<int>',
name: 'items',
atomName: '_itemsAtom',
useDeepEquality: null,
);
final output = template.toString();
expect(output, isNot(contains('useDeepEquality')));
});
Comment thread
ben-milanko marked this conversation as resolved.
Outdated
});
}
Loading