Pete, what would you (or anyone) suggest if the user is updating 
filteredArray (and therefore baseArray has to be kept in synch)?

On Saturday, 20 October 2012 21:15:01 UTC+2, Pete Bacon Darwin wrote:
>
> You should never really $watch anything that is doing serious calculation. 
>  Simple computed values seem reasonable enough but I would steer clear of 
> $watching a filtered array, since this will be rebuilt every time a $digest 
> runs, in fact multiple times (at least two) for each digest. So I would 
> lean toward this kind of $watch...
>
> $watch(smallFastFunction, fatSlowFunction);
>
> In you case I would do a $watch on the base array and build the filtered 
> array when it changes:
>
> $scope.$watch(
>   function() { return $scope.baseArray; },
>   function() { $scope.filteredArray = doFilter($scope.baseArray); },
>   true);
>
> Then bind your UI to $scope.filteredArray.  That way, every time the 
> digest runs, it is only doing a check that the baseArray has not changed, 
> and not re-running the doFilter function over and over.
>
> Pete
>
> On 20 October 2012 18:41, Per Rovegård <[email protected]<javascript:>
> > wrote:
>
>> My performance problem has do to with using a filter for all values in a 
>> particular column in the table. It's easy enough for me to add a 
>> pre-processing step and apply the filter in advance, but it makes the 
>> solution a bit less flexible (when the source data changes, it must be 
>> re-processed).
>>
>> So my conclusion is that filters and anything else that involves 
>> calculation should be avoided inside an ng-repeat if you care about 
>> performance. Would you agree?
>>
>> Per
>>
>>
>> On Saturday, October 20, 2012 7:16:00 PM UTC+2, Peter Bacon Darwin wrote:
>>
>>> Sorry. I wasn't clear.
>>> When the value of the expression changes.
>>>
>>> Pete
>>> ...from my mobile.
>>> On Oct 20, 2012 5:41 PM, "Per Rovegård" <[email protected]> wrote:
>>>
>>>> But the ng-repeat expression doesn't change.
>>>>
>>>> Per
>>>>
>>>> On Saturday, October 20, 2012 5:36:34 PM UTC+2, Peter Bacon Darwin 
>>>> wrote:
>>>>>
>>>>> No this is how angular data binding works. Just calc the values and 
>>>>> store them when the ng-repeat expression changes.
>>>>> Then bind to these values.
>>>>> Pete
>>>>> ...from my mobile.
>>>>> On Oct 20, 2012 4:29 PM, "Per Rovegård" <[email protected]> 
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have a page with a table populated using ng-repeat. On the page I 
>>>>>> also have a form where the user can type some data. I've run into a 
>>>>>> performance problem, where each key press in the form causes the entire 
>>>>>> table to be re-calculated. I can fix this particular performance problem 
>>>>>> quite easily, but I started to wonder *why* the re-calculation happens. 
>>>>>> The 
>>>>>> following fiddle illustrates the problem:
>>>>>>
>>>>>> http://jsfiddle.net/provegard/ETerq/8/
>>>>>>
>>>>>> For each key press in the input element, Angular fetches the 
>>>>>> data-bound properties within the ng-repeat.
>>>>>>
>>>>>> Is there a way for me to indicate that the values within the 
>>>>>> ng-repeat won't change as long as the repeat expression doesn't change?
>>>>>>
>>>>>> Cheers,
>>>>>> Per
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "AngularJS" group.
>>>>>> To post to this group, send email to [email protected].
>>>>>> To unsubscribe from this group, send email to angular+u...@
>>>>>> googlegroups.com.
>>>>>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>>>>>  
>>>>>>  
>>>>>>
>>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "AngularJS" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to angular+u...@
>>>> googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>>>  
>>>>  
>>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "AngularJS" group.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> [email protected] <javascript:>.
>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to