Extra hint for Multiplier Filter in "Explore More", chapter 5 #34
Description
I'm trying to do the Multiplier Filter at the end of chapter 5. The challenge is to write a filter which lets a user enter a multiplier, and have item quantities multiplied by that value on output.
My first attempt failed because the filter was modifying the original recipe instead of a copy for output, so values would keep multiplying over and over again. I tried having the filter construct new recipe models and return a List of those, but that threw it into a loop involving Scope / $watchCollection resulting in an error:
5 $digest() iterations reached. Aborting!
Watchers fired in the last 3 iterations: [["recipe in ctrl.recipes | orderBy:'name' | filter:{name:ctrl.nameFilterString} | categoryfilter:ctrl.categoryFilterMap | multiplierfilter:ctrl.multiplier ","ctrl.tooltipForRecipe(recipe)","recipe.rating","rating","FN: eval(scope) {\n try {\n return _expression.eval(scope);\n } on EvalError catch (e, s) {\n throw e.unwrap("$this", s);\n }\n }","ctrl.tooltipForRecipe(recipe)","recipe.rating","rating","FN: eval(scope) {\n try {\n return _expression.eval(scope);\n } on EvalError catch... (this catch bit repeats many times)STACKTRACE:
0 Scope._digestWhileDirtyLoop (package:angular/core/scope.dart:466:5)
1 Scope.$digest (package:angular/core/scope.dart:415:28)
2 _autoDigestOnTurnDone (package:angular/core/scope.dart:108:14)
3 _rootRun (dart:async/zone.dart:688)
4 _ZoneDelegate.run (dart:async/zone.dart:417)
5 NgZone._finishTurn (package:angular/core/zone.dart:97:21)
6 NgZone._onRunBase (package:angular/core/zone.dart:57:20)
7 _onRunUnary (package:angular/core/zone.dart:66:22)
8 _ZoneDelegate.runUnary (dart:async/zone.dart:426)
9 _CustomizedZone.runUnary (dart:async/zone.dart:631)
10 _BaseZone.runUnaryGuarded (dart:async/zone.dart:546)
11 _BaseZone.bindUnaryCallback. (dart:async/zone.dart:572)
This repeats indefinitely until I stop it. It seems that having the filter return a different list causes it to re-evaluate the ng-repeat, and this goes on forever.
I'm pretty new to Dart and loving it, but I'd really appreciate an extra hint as to how I can better approach this. I've got my current stab at it in this gist: https://gist.github.com/zymsys/8479765