allaud / quick-ng-repeat

A much more quicker replacement for AngularJS ng-repeat directive

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation needed on quick-repeat-list

djsmith42 opened this issue · comments

What is quick-repeat-list intended for? Does each of my quick-ng-repeat instances need a unique quick-repeat-list value?

@djsmith42
quickRepeatList attribute contains a key name for hash storing $watch callbacks. While linking a new directive, we store a reference to $watch callback in that hash using quickRepeatList attribute:

https://github.com/allaud/quick-ng-repeat/blob/master/quick-ng-repeat.js#L126

And the next time we need to refresh our list we don't need to wait for digest cycle (which is usually heavy, moreover it is done synchronously). Instead we can call this callback manually and asynchronously:

https://github.com/allaud/quick-ng-repeat/blob/master/example/js/main.js#L53

This allows us to make a heavy list render without blocking ui (and many more things, redraw some lists eventually for example, without redrawing the whole application).

So, the answer to your questing is - yes, most of the time you should use uniq names for that attribute. But I also can imagine some rare situations, when you need to replace one watcher callback with another.

Why wouldn't you generate unique one yourself if you need it pretty much every time ?

@ojosdegris can you show the line of code you are speaking about?

@allaud I'm talking about quick-repeat-list directive, if it is better to have it every time, why not to generate unique value for it inside main directive ?

@ojosdegris this the the code from html:

<div quick-ng-repeat="item in list" quick-repeat-list="items">

And this is the code from main.js , which contains some lazy-load logic:
https://github.com/allaud/quick-ng-repeat/blob/master/example/js/main.js#L53

 _.defer(quickRepeatList.items, $scope.list);

Specifying this name lets us to call from our code directly the list we want to operate with.

Then is there a way to supply this parameter dynamically?

I'm using quick-ng-repeat in a template that is used twice on the same page. Each instance needs a unique quick-repeat-list value, but because this is in a template, I can't supply two different values. If I use a scope variable like this it doesn't work: quick-repeat-list="[[ myQuickRepeatList ]]".

I realize that this parameter is necessary to refer to your list in javascript, but if I understand it correctly, the current setup still seems not ideal since it makes the plugin unusable in my case. If there's no way to supply quick-repeat-list dynamically, would it be better to store watch callbacks as an array of objects instead?

Agreed, this doesn't seem like something that the developer should need to set for 99% of cases. The directive should generate its own unique values unless explicitly specified.

@justinmc @leisms accepted, the fix is coming

@justinmc @leisms this addition should do the trick: b5e51ac

I think you mistyped from one copy of the quick-ng-repeat.js file to the other, check out my pull request.

After applying my pull request, this works for my use case. Thanks for the quick fix, I think it's much better like this! Now if you want to updated all instances, you can do something like this:

for (var key in quickRepeatList) { 
    quickRepeatList[key](mydata); 
}

This is really useful when you have multiple instances of quick-ng-repeat operating on the same data, especially when you're unable to assign unique quick-repeat-list parameters like I was.

@justinmc yep, this was my mistake, thanks for contributing. I think, we can close this issue

It may be worth mentioning here that issue #9 addresses some of the use cases mentioned in this thread. The change will give you more flexibility in naming dynamically-generated lists so you can retrieve them later.

@Adarsh456 Your code is missing!

Thank a lot....It get me rid of performance issues in IE8.

commented

I want to repeat the hierarchical data using quick-ng-repeat. How can i do this?

This is going on in: vm.FilteredData = $filter('filter')(vm.data, { CategoryId: vm.currentCategory.id });

All I get is one empty item. What could I be doing wrong here? Is it because of quick-repeat-list?