Skip to content

Commit 4e53f73

Browse files
committed
feat(ngPluralize): support the new interpolation service
This commit also: - remove the previously registered watch, - add an expression cache
1 parent 508d35a commit 4e53f73

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/directive/ng_pluralize.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class NgPluralizeDirective {
9595
int offset;
9696
final discreteRules = <String, String>{};
9797
final categoryRules = <Symbol, String>{};
98+
final expressionCache = <String, String>{};
99+
Watch _watch;
98100

99101
static final RegExp IS_WHEN = new RegExp(r'^when-(minus-)?.');
100102
static const Map<String, Symbol> SYMBOLS = const {
@@ -164,10 +166,14 @@ class NgPluralizeDirective {
164166
}
165167
}
166168

167-
_setAndWatch(expression) {
168-
var interpolation = interpolate(expression, false, r'${', '}');
169-
interpolation.setter = (text) => element.text = text;
170-
interpolation.setter(expression);
171-
scope.watch(interpolation.expressions, interpolation.call);
169+
void _setAndWatch(template) {
170+
if (_watch != null) _watch.remove();
171+
var expression = expressionCache.putIfAbsent(template, () =>
172+
interpolate(template, false, r'${', '}'));
173+
_watch = scope.watch(expression, _updateMarkup);
174+
}
175+
176+
void _updateMarkup(text, previousText) {
177+
if (text != previousText) element.text = text.toString();
172178
}
173179
}

0 commit comments

Comments
 (0)