Pasvaz / bindonce

Zero watches binding for AngularJs
2.73k stars 278 forks source link

bindonce repeater #10

Open elemoine opened 11 years ago

elemoine commented 11 years ago

ng-repeat registers a collection watcher (with $watchCollection), which can be costly, especially when considering ng-repeat based recursive directives (as in http://jsfiddle.net/n8dPm/).

I was wondering if a bindonce type repeater would make sense. That repeater would wait for the collection to be there, but wouldn't shallow-watch the collection.

Not sure it makes sense. Feel free to close this issue if it doesn't. Thanks.

Pasvaz commented 11 years ago

Yes it makes sense, I've been thinking a lot about creating bo-repeat in order to get rid of the watcher but not only for that, a repeater uses one watcher ($watchCollection as you said) but what makes it expensive in term of performances is the creation of a child scope for each item, in case of large set can be costly. Now bo-* fields can live without child scopes because once the item is drawn even if the scope change it is no longer bound with the scope, but if you use any ng-* field inside the bo-repeater you immediately run into scope issues. However we can try to deal with this is it is necessary...

akarelas commented 11 years ago

:+1:. I found many cases in my websites where I'd need to use that.

adamkdean commented 10 years ago

:+1: It would be one of the most useful cases, especially when grids loop through rows and columns.

FGRibreau commented 10 years ago

:+1:

mendelk commented 10 years ago

:+1:

evilaliv3 commented 10 years ago

:+1:

MWallenberg commented 10 years ago

I need this in my life. But mostly, I need it in my code... Pasvaz, any time you spend towards making this a reality would be much appreciated :)

Pasvaz commented 10 years ago

Hi @MWallenberg, this will be the next step, right now I'm focusing on the rebind feature, when the new binding system will work flawlessy it shouldn't be a problem to implement a repeater.

pgayvallet commented 10 years ago

+1, would be awesome to have

mparpaillon commented 10 years ago

:+1:

philippzentner commented 10 years ago

:+1:

schickling commented 10 years ago

:+1: looking forward to this feature

fidoboy commented 10 years ago

:+1:

steve8708 commented 10 years ago

+1

akarelas commented 10 years ago

I believe that Angular 1.3 solves this problem, like so:

<li ng-repeat="item in ::items">{{::item.name}}</li>
michael-wynn commented 10 years ago

akarelas, I looked at Angular 1.3 documentation and don't see any mention of the syntax you posted. Where do get that from?

akarelas commented 10 years ago

@michael-wynn I don't know where I learned it from (maybe from the Changelog of Angular 1.3) but it works.

lorenzhs commented 10 years ago

@michael-wynn @akarelas https://docs.angularjs.org/guide/expression#one-time-binding

michael-wynn commented 10 years ago

Thank you!

From: Lorenz Hübschle-Schneider [mailto:notifications@github.com] Sent: Saturday, August 23, 2014 3:45 AM To: Pasvaz/bindonce Cc: michael-wynn Subject: Re: [bindonce] bindonce repeater (#10)

@michael-wynn https://github.com/michael-wynn @akarelas https://github.com/akarelas https://docs.angularjs.org/guide/expression#one-time-binding

— Reply to this email directly or view it on GitHub https://github.com/Pasvaz/bindonce/issues/10#issuecomment-53149458 . https://github.com/notifications/beacon/4787565__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNDQwOTkyMiwiZGF0YSI6eyJpZCI6MTM5NjQxOTF9fQ==--355d83e1f1550465505a3205688358a9af8b503f.gif

lorenzhs commented 10 years ago

In fact, I replaced bindonce with Angular one-time bindings in Glowing Bear yesterday: https://github.com/glowing-bear/glowing-bear/pull/418

It started with adding :: to ng-repeat statements, but it soon emerged that we could drop bindonce altogether, as we're using angular 1.3 beta in production :bomb: Now we have one less dependency (even if it was only 6.5k minified). Sorry to abandon you ;)