1

I want to understand how Chained Filters/Formatters execution in AngularDart via ng-repeat Directive work.

Can anyone explain how it works in clear and concise manner?

The referenced tutorial does not provide enough detail to get a completely grasp how AngularDart Chained Filter execution works. Below is what I understood from looking at documentation and reviewing portions of AngularDart source code.

Reference Link: http://runnable.com/UvL5t92j1pVCAAAQ/angular-dart-tutorial-chapter-05 original github post: https://github.com/angular/angular.dart.tutorial/issues/74

** Presumed Chain of Execution for Evaluating filters in ng-repeat**

Formatters/Filters gain access to list inside repeaters, such as ng-repeat

recipeList is provided via ng-repeat's scope to cf

cf=categoryfilter(list, map) --> categorizedList

fltr=filter (list, nameFilterString)--> filteredList, name

ordBy=orderBy(list, name)--> orderdList

  1. First get categories selected by user, pass list to next filter
  2. Filter on Inputted text with dependency on categories selected
  3. Order the list which was Filtered in 2 above base on default ascending order by name
  4. Create a html span for each item in list

Html View (from right to left: 1., 2., 3., 4. as indicated below):

< 4.ng-repeat=recipe in ordererdList | <==3.ordBy(fltr) | <== 2.fltr(cf, nameFilterstring) | <== 1. cf(recipeList , map < category, isChecked > ) >

I want to know how Lists (recipeList) in an angularDart repeater (ng-repeat) passes the list to each consecutive Chained Filter and confirm whether or not order of filters does matter (I believe they do). Is my understanding indicated above correct?

< li class="pointer"
          ng-repeat="recipe in ctrl.recipes | orderBy:'name' | filter:{name:ctrl.nameFilterString} | categoryfilter:ctrl.categoryFilterMap" >
.... repeated dom elements omitted here for clarity
< /li >    
KK.
  • 693
  • 6
  • 15

1 Answers1

0

The formatters int the expression are in the order

  1. orderBy
  2. filter
  3. categoryfilter

Initially they are called in exactly this order

orderby gets passed

[Appetizers, Salads, Soups, Main Dishes, Side Dishes, Desserts, Desserts]

and returns

[Desserts, Appetizers, Salads, Desserts, Side Dishes, Soups, Main Dishes]

which is passed to the categoryfilter unchanged (because no filter value is set yet)
categoryfilter again returns the collection unchanged

After selecting a category only the category formatter is called.
After entering a name (a value for the filter expression) the filter and the categoryfilter formatters are called. Changing the name filter value sometimes triggers only the filter but sometimes also the categoryfilter formatter.

The order the formatters are called is always the same as they appear in the markup, but not each filter is called every time. Angular recognized dependencies and only calls the filters when a dependent value has been changed.

EDIT

The result of this expression is passed to ng-repeat

ctrl.recipes | orderBy:'name' | filter:{name:ctrl.nameFilterString} | categoryfilter:ctrl.categoryFilterMap

ctrl.receipes is passed to all filters and the result of the last filter is passed to ng-repeat

EDIT2

I just copy the findings reported from KK:

I confirmed the behavior in the debugger. It appears that there should be a slight correction to your answer. orderBy returns its changed list and passes it to filter even if nothing is entered in filter input textbox. Then filter processes null for the input textbox field value. Then filter passes the list unchanged to categoryfilter after which categoryfilter passes the list to ng-repeat.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Hi Günter, I tried to confirm behavior via debugger by placing break points in categoryfilter.dart and the angular filters: orderBy, filter and ng-repeat via Dart Editor however code execution does not stop @breakpoints in Editor. How did you confirm the behavior above? – KK. Aug 21 '14 at 03:54
  • I'm not sure if you mean something special with `@breakpoints`. But otherwise this is what I did. I set a breakpoint at the first line inside the `call()` method of the Filter, SortBy, and CategoryFilter class. I had troubles with several DartEditor version not stopping at breakpoints in the past but otherwise it should just work. – Günter Zöchbauer Aug 21 '14 at 04:28
  • 1
    Hi Günter, it appears I had multiple instances of Dartium running which apparently prevented debugger from executing correctly. After I closed all instances and restarted the Editor started in Debug mode. Thanks Again! – KK. Aug 21 '14 at 05:53
  • 1
    Hi Günter, I confirmed behavior in debugger it appears that there should be a slight correction to answer above. **ordBy** returns its changed list and passes it to **filter** even if nothing is entered in filter input textbox. Then **filter** processes null for input textbox field value. Then **filter** passes list AsIs to **categoryfilter** after which **categoryfilter** passes list to ng-repeat. – KK. Aug 21 '14 at 10:23
  • I hope it's fine with you when I just copy your comment. – Günter Zöchbauer Aug 21 '14 at 10:29