From 6c90b66233e1f887a67d25bb2c5135d180984062 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Fri, 17 Jan 2020 02:45:04 +1100 Subject: [PATCH] Fix naming of tracking function argument in reaction (#398) * correct naming of tracking function argument * update docs with corrected naming of tracking function * update reaction tests to mention tracking function instead of predicate --- docs/src/api/reaction.mdx | 6 +++--- docs/src/core-concepts.mdx | 6 +++--- mobx/README.md | 6 +++--- mobx/lib/src/api/reaction.dart | 15 +++++++-------- mobx/lib/src/core/reaction_helper.dart | 6 +++--- mobx/test/autorun_test.dart | 2 +- mobx/test/reaction_test.dart | 10 +++++----- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/docs/src/api/reaction.mdx b/docs/src/api/reaction.mdx index 1bfba7518..328b2e6ce 100644 --- a/docs/src/api/reaction.mdx +++ b/docs/src/api/reaction.mdx @@ -47,10 +47,10 @@ dispose(); ## reaction -### `ReactionDisposer reaction(T Function(Reaction) predicate, void Function(T) effect)` +### `ReactionDisposer reaction(T Function(Reaction) fn, void Function(T) effect)` -Monitors the observables used inside the `predicate()` function and runs the `effect()` when -the predicate returns a different value. Only the observables inside `predicate()` are tracked. +Monitors the observables used inside the `fn()` tracking function and runs the `effect()` when +the tracking function returns a different value. Only the observables inside `fn()` are tracked. ```dart import 'package:mobx/mobx.dart'; diff --git a/docs/src/core-concepts.mdx b/docs/src/core-concepts.mdx index ab38a0422..775c617e7 100644 --- a/docs/src/core-concepts.mdx +++ b/docs/src/core-concepts.mdx @@ -191,10 +191,10 @@ dispose(); // Hello MobX ``` -**`ReactionDisposer reaction(T Function(Reaction) predicate, void Function(T) effect)`** +**`ReactionDisposer reaction(T Function(Reaction) fn, void Function(T) effect)`** -Monitors the observables used inside the `predicate()` function and runs the `effect()` when -the predicate returns a different value. Only the observables inside `predicate()` are tracked. +Monitors the observables used inside the `fn()` function and runs the `effect()` when +the tracking function returns a different value. Only the observables inside `fn()` are tracked. ```dart import 'package:mobx/mobx.dart'; diff --git a/mobx/README.md b/mobx/README.md index 25f8c5cee..f49e4e79d 100644 --- a/mobx/README.md +++ b/mobx/README.md @@ -221,10 +221,10 @@ dispose(); // Hello MobX ``` -**`ReactionDisposer reaction(T Function(Reaction) predicate, void Function(T) effect)`** +**`ReactionDisposer reaction(T Function(Reaction) fn, void Function(T) effect)`** -Monitors the observables used inside the `predicate()` function and runs the `effect()` when -the predicate returns a different value. Only the observables inside `predicate()` are tracked. +Monitors the observables used inside the `fn()` function and runs the `effect()` when +the `fn()` function returns a different value. Only the observables inside `fn()` are tracked. ```dart import 'package:mobx/mobx.dart'; diff --git a/mobx/lib/src/api/reaction.dart b/mobx/lib/src/api/reaction.dart index 1265ba833..06c82df47 100644 --- a/mobx/lib/src/api/reaction.dart +++ b/mobx/lib/src/api/reaction.dart @@ -31,28 +31,27 @@ ReactionDisposer autorun(Function(Reaction) fn, createAutorun(context ?? mainContext, fn, name: name, delay: delay, onError: onError); -/// Executes the [predicate] function and tracks the observables used in it. Returns +/// Executes the [fn] function and tracks the observables used in it. Returns /// a function to dispose the reaction. /// -/// The [predicate] is supposed to return a value of type T. When it changes, the +/// The [fn] is supposed to return a value of type T. When it changes, the /// [effect] function is executed. /// -/// *Note*: Only the [predicate] function is tracked and not the [effect]. +/// *Note*: Only the [fn] function is tracked and not the [effect]. /// /// You can also pass in an optional [name], a debouncing [delay] in milliseconds. Use /// [fireImmediately] if you want to invoke the effect immediately without waiting for -/// the [predicate] to change its value. It is possible to define a custom [equals] function -/// to override the default comparison for the value returned by [predicate], to have fined +/// the [fn] to change its value. It is possible to define a custom [equals] function +/// to override the default comparison for the value returned by [fn], to have fined /// grained control over when the reactions should run. -ReactionDisposer reaction( - T Function(Reaction) predicate, void Function(T) effect, +ReactionDisposer reaction(T Function(Reaction) fn, void Function(T) effect, {String name, int delay, bool fireImmediately, EqualityComparator equals, ReactiveContext context, void Function(Object, Reaction) onError}) => - createReaction(context ?? mainContext, predicate, effect, + createReaction(context ?? mainContext, fn, effect, name: name, delay: delay, equals: equals, diff --git a/mobx/lib/src/core/reaction_helper.dart b/mobx/lib/src/core/reaction_helper.dart index 2a3f05f31..c934d9697 100644 --- a/mobx/lib/src/core/reaction_helper.dart +++ b/mobx/lib/src/core/reaction_helper.dart @@ -65,8 +65,8 @@ ReactionDisposer createAutorun( } /// An internal helper function to create a [reaction] -ReactionDisposer createReaction(ReactiveContext context, - T Function(Reaction) predicate, void Function(T) effect, +ReactionDisposer createReaction( + ReactiveContext context, T Function(Reaction) fn, void Function(T) effect, {String name, int delay, bool fireImmediately, @@ -93,7 +93,7 @@ ReactionDisposer createReaction(ReactiveContext context, var changed = false; rxn.track(() { - final nextValue = predicate(rxn); + final nextValue = fn(rxn); // Use the equality-comparator if provided final isEqual = diff --git a/mobx/test/autorun_test.dart b/mobx/test/autorun_test.dart index ea7a9e131..69558551f 100644 --- a/mobx/test/autorun_test.dart +++ b/mobx/test/autorun_test.dart @@ -99,7 +99,7 @@ void main() { dispose(); }); - test('with pre-mature disposal in predicate', () { + test('with pre-mature disposal in tracking function', () { final x = Observable(10); final d = autorun((reaction) { diff --git a/mobx/test/reaction_test.dart b/mobx/test/reaction_test.dart index 5d7b638c3..8dc0ac5de 100644 --- a/mobx/test/reaction_test.dart +++ b/mobx/test/reaction_test.dart @@ -89,7 +89,7 @@ void main() { fakeAsync((async) { x.value = 11; - // Even though predicate has changed, effect should not be executed + // Even though tracking function has changed, effect should not be executed expect(executed, isFalse); async.elapse(const Duration(milliseconds: 500)); expect( @@ -127,7 +127,7 @@ void main() { // Effect should be executed, as we are forcing an immediate change even though there is a delay expect(executed, isTrue); - x.value = 11; // predicate goes from false -> true + x.value = 11; // tracking function goes from false -> true executed = false; async.elapse(const Duration(milliseconds: 500)); @@ -139,7 +139,7 @@ void main() { expect(executed, isTrue); executed = false; - // predicate goes from true -> false, but effect should not run for next 1s + // tracking function goes from true -> false, but effect should not run for next 1s x.value = 9; expect(executed, isFalse); @@ -151,7 +151,7 @@ void main() { }); }); - test('with pre-mature disposal in predicate', () { + test('with pre-mature disposal in tracking function', () { final x = Observable(10); var executed = false; @@ -175,7 +175,7 @@ void main() { d(); }); - test('fires onError on exception inside predicate', () { + test('fires onError on exception inside tracking function', () { var thrown = false; final dispose = reaction( (_) {