forked from mobxjs/mobx.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds support for annotations (mobxjs#904)
* fix: Example FormStore importing non-existent file Signed-off-by: Hugo Branco <[email protected]> * feat: Inherited annotations for actions, observables futures and observable stream Closes mobxjs#899 Signed-off-by: Hugo Branco <[email protected]> * ci: Replaces implicit-casts for strict-casts implicit-casts was deprecated in dart's 2.16 Signed-off-by: Hugo Branco <[email protected]> --------- Signed-off-by: Hugo Branco <[email protected]>
- Loading branch information
1 parent
d99a5c6
commit b3c9ad2
Showing
19 changed files
with
372 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!! | ||
|
||
/// The current version as per `pubspec.yaml`. | ||
const version = '2.1.4'; | ||
const version = '2.1.4'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
mobx_codegen/lib/src/template/annotations_generator_mixin.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
mixin AnnotationsGenerator { | ||
bool hasProtected = false; | ||
bool hasVisibleForOverriding = false; | ||
bool hasVisibleForTesting = false; | ||
|
||
String get annotations { | ||
final List<String> annotations = ['@override']; | ||
|
||
if (hasProtected) { | ||
annotations.add('@protected'); | ||
} | ||
|
||
if (hasVisibleForOverriding) { | ||
annotations.add('@visibleForOverriding'); | ||
} | ||
|
||
if (hasVisibleForTesting) { | ||
annotations.add('@visibleForTesting'); | ||
} | ||
|
||
return annotations.join('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.1.1'; | ||
const version = '2.2.0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
library generator_sample; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:mobx/mobx.dart'; | ||
|
||
part 'generator_sample.g.dart'; | ||
|
||
class AnnotationsTestClass = AnnotationsTestClassBase | ||
with _$AnnotationsTestClass; | ||
|
||
abstract class AnnotationsTestClassBase with Store { | ||
AnnotationsTestClassBase(this.foo); | ||
|
||
@observable | ||
String foo = ''; | ||
|
||
@action | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
void actionAnnotated() { | ||
foo = 'Action annotated'; | ||
} | ||
|
||
@action | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
Future<void> asyncActionAnnotated() async { | ||
foo = 'AsyncAction annotated'; | ||
} | ||
|
||
@action | ||
@observable | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
Future<void> observableFutureAnnotated() async { | ||
foo = 'ObservableFuture annotated'; | ||
} | ||
|
||
@observable | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
Stream<String> observableStreamAnnotated() async* { | ||
yield 'ObservableFuture annotated'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
mixin _$AnnotationsTestClass on AnnotationsTestClassBase, Store { | ||
late final _$fooAtom = | ||
Atom(name: 'AnnotationsTestClassBase.foo', context: context); | ||
|
||
@override | ||
String get foo { | ||
_$fooAtom.reportRead(); | ||
return super.foo; | ||
} | ||
|
||
@override | ||
set foo(String value) { | ||
_$fooAtom.reportWrite(value, super.foo, () { | ||
super.foo = value; | ||
}); | ||
} | ||
|
||
@override | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
ObservableStream<String> observableStreamAnnotated() { | ||
final _$stream = super.observableStreamAnnotated(); | ||
return ObservableStream<String>(_$stream, context: context); | ||
} | ||
|
||
late final _$asyncActionAnnotatedAsyncAction = AsyncAction( | ||
'AnnotationsTestClassBase.asyncActionAnnotated', | ||
context: context); | ||
|
||
@override | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
Future<void> asyncActionAnnotated() { | ||
return _$asyncActionAnnotatedAsyncAction | ||
.run(() => super.asyncActionAnnotated()); | ||
} | ||
|
||
late final _$observableFutureAnnotatedAsyncAction = AsyncAction( | ||
'AnnotationsTestClassBase.observableFutureAnnotated', | ||
context: context); | ||
|
||
@override | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
ObservableFuture<void> observableFutureAnnotated() { | ||
return ObservableFuture<void>(_$observableFutureAnnotatedAsyncAction | ||
.run(() => super.observableFutureAnnotated())); | ||
} | ||
|
||
late final _$AnnotationsTestClassBaseActionController = | ||
ActionController(name: 'AnnotationsTestClassBase', context: context); | ||
|
||
@override | ||
@protected | ||
@visibleForOverriding | ||
@visibleForTesting | ||
void actionAnnotated() { | ||
final _$actionInfo = _$AnnotationsTestClassBaseActionController.startAction( | ||
name: 'AnnotationsTestClassBase.actionAnnotated'); | ||
try { | ||
return super.actionAnnotated(); | ||
} finally { | ||
_$AnnotationsTestClassBaseActionController.endAction(_$actionInfo); | ||
} | ||
} | ||
|
||
@override | ||
String toString() { | ||
return ''' | ||
foo: ${foo} | ||
'''; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.