Skip to content

Commit 46878c3

Browse files
committed
feat(scope): Remove Scope.watch's context parameter.
BREAKING CHANGE Scope.watch can no longer switch context. Instead of saying scope.watch(expression, (v, _) { }, context: o); Create a new isolate child scope scope.createChild(o).watch(expression, (v, _) { });
1 parent 5c8d03e commit 46878c3

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

lib/core/scope.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ class Scope {
200200
* evaluates to a non-null value.
201201
* * [reactionFn]: The reaction function to execute when a change is detected in the watched
202202
* expression.
203-
* * [context]: The object against which the expression is evaluated. This defaults to the
204-
* [Scope.context] if no context is specified.
205203
* * [formatters]: If the watched expression contains formatters,
206204
* this map specifies the set of formatters that are used by the expression.
207205
* * [canChangeModel]: Specifies whether the [reactionFn] changes the model. Reaction
@@ -212,8 +210,8 @@ class Scope {
212210
* by reference. When watching a collection, the reaction function receives a
213211
* [CollectionChangeItem] that lists all the changes.
214212
*/
215-
Watch watch(String expression, ReactionFn reactionFn, {context,
216-
FormatterMap formatters, bool canChangeModel: true, bool collection: false}) {
213+
Watch watch(String expression, ReactionFn reactionFn,
214+
{FormatterMap formatters, bool canChangeModel: true, bool collection: false}) {
217215
assert(isAttached);
218216
assert(expression is String);
219217
assert(canChangeModel is bool);
@@ -239,7 +237,7 @@ class Scope {
239237
}
240238
}
241239

242-
AST ast = rootScope._astParser(expression, context: context,
240+
AST ast = rootScope._astParser(expression,
243241
formatters: formatters, collection: collection);
244242

245243
WatchGroup group = canChangeModel ? _readWriteGroup : _readOnlyGroup;
@@ -1052,14 +1050,10 @@ class _AstParser {
10521050
: _visitor = new ExpressionVisitor(closureMap);
10531051

10541052
AST call(String input, {FormatterMap formatters,
1055-
bool collection: false,
1056-
Object context: null }) {
1053+
bool collection: false }) {
10571054
_visitor.formatters = formatters;
10581055
AST contextRef = _visitor.contextRef;
10591056
try {
1060-
if (context != null) {
1061-
_visitor.contextRef = new ConstantAST(context, '#${_id++}');
1062-
}
10631057
var exp = _parser(input);
10641058
return collection ? _visitor.visitCollection(exp) : _visitor.visit(exp);
10651059
} finally {

test/core/scope_spec.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,17 +1020,6 @@ void main() {
10201020
expect(log).toEqual(['misko', null]);
10211021
});
10221022

1023-
1024-
it('should watch/observe on objects other then contex', (RootScope rootScope) {
1025-
var log = '';
1026-
var map = {'a': 'A', 'b': 'B'};
1027-
rootScope.watch('a', (a, b) => log += a, context: map);
1028-
rootScope.watch('b', (a, b) => log += a, context: map);
1029-
rootScope.apply();
1030-
expect(log).toEqual('AB');
1031-
});
1032-
1033-
10341023
it(r'should watch and fire on expression change', (RootScope rootScope) {
10351024
var log;
10361025

0 commit comments

Comments
 (0)