-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add `nonObservableInner`, such that users can bypass observability system for performance * chore: format code * feat: Add `onDispose` callback to `Computed`, such that old values can be properly disposed #857 * test: add tests to `disposeValue` #857 * test: add tests for "Allow users to bypass observability system for performance" * feat: add `Computed.dispose` #859 * test: add tests for Computed.dispose * test: reproduce #855 * fix: Avoid unnecessary observable notifications of `@observable` fields of `Store`s #855 * Revert "test: add tests for Computed.dispose" This reverts commit 63d57ef. * Revert "feat: add `Computed.dispose` #859" This reverts commit 20fe5d3. * Revert "test: add tests to `disposeValue` #857" This reverts commit 263155b. # Conflicts: # mobx/test/computed_test.dart * Revert "feat: Add `onDispose` callback to `Computed`, such that old values can be properly disposed #857" This reverts commit bbd9020. * format code and minor change to code * add Observable.nonObservableValue * fix: Reaction lacks toString, so cannot see which reaction causes the error #864 * feat: Add StackTrace to reactions in debug mode to easily spot which reaction it is #864 * fix linter errors * add toString and debugCreationStack * test: add atom_test --------- Co-authored-by: fzyzcjy <ch271828n@outlook.com> Co-authored-by: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com>
- Loading branch information
1 parent
558449a
commit d99a5c6
Showing
24 changed files
with
273 additions
and
6 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
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
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
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,5 @@ | ||
// Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!! | ||
|
||
/// The current version as per `pubspec.yaml`. | ||
const version = '2.1.3+1'; | ||
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
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,61 @@ | ||
import 'package:mobx/mobx.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test( | ||
'when write to @observable field with changed value, should trigger notifications for downstream', | ||
() { | ||
final store = _ExampleStore(); | ||
|
||
final autorunResults = <String>[]; | ||
autorun((_) => autorunResults.add(store.value)); | ||
|
||
expect(autorunResults, ['first']); | ||
|
||
store.value = 'second'; | ||
|
||
expect(autorunResults, ['first', 'second']); | ||
}); | ||
|
||
// fixed by #855 | ||
test( | ||
'when write to @observable field with unchanged value, should not trigger notifications for downstream', | ||
() { | ||
final store = _ExampleStore(); | ||
|
||
final autorunResults = <String>[]; | ||
autorun((_) => autorunResults.add(store.value)); | ||
|
||
expect(autorunResults, ['first']); | ||
|
||
store.value = store.value; | ||
|
||
expect(autorunResults, ['first']); | ||
}); | ||
} | ||
|
||
class _ExampleStore = __ExampleStore with _$_ExampleStore; | ||
|
||
abstract class __ExampleStore with Store { | ||
@observable | ||
String value = 'first'; | ||
} | ||
|
||
// This is what typically a mobx codegen will generate. | ||
mixin _$_ExampleStore on __ExampleStore, Store { | ||
// ignore: non_constant_identifier_names | ||
late final _$valueAtom = Atom(name: '__ExampleStore.value', context: context); | ||
|
||
@override | ||
String get value { | ||
_$valueAtom.reportRead(); | ||
return super.value; | ||
} | ||
|
||
@override | ||
set value(String value) { | ||
_$valueAtom.reportWrite(value, super.value, () { | ||
super.value = value; | ||
}); | ||
} | ||
} |
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,31 @@ | ||
import 'package:mobx/mobx.dart'; | ||
import 'package:mobx/src/utils.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'util.dart'; | ||
|
||
void main() { | ||
testSetup(); | ||
|
||
group('Atom', () { | ||
test('toString', () { | ||
final object = Atom(name: 'MyName'); | ||
expect(object.toString(), contains('MyName')); | ||
}); | ||
|
||
test('debugCreationStack', () { | ||
DebugCreationStack.enable = true; | ||
addTearDown(() => DebugCreationStack.enable = false); | ||
final object = Atom(); | ||
expect(object.debugCreationStack, isNotNull); | ||
}); | ||
|
||
test('isBeingObserved', () { | ||
final observable = Observable(1, name: 'MyName'); | ||
expect(observable.isBeingObserved, false); | ||
final d = autorun((_) => observable.value); | ||
expect(observable.isBeingObserved, true); | ||
d(); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.