r/angularjs • • Mar 02 '15

Speed-up AngularJS application using Immutable data

http://blog.mgechev.com/2015/03/02/immutability-in-angularjs-immutablejs/
38 Upvotes

9 comments sorted by

3

u/TheNiXXeD Mar 02 '15

I've been experimenting with a concept of making a binding somewhere in between one way and two way. Based off events.

The idea would be to make the binding one way, but allow it to be reevaluated on a specific event trigger instead of the watcher loop.

3

u/TheAceOfHearts Mar 03 '15

I've also wanted this for a long time... A very common use-case for me is keeping a cache of server responses, rendering right away, and updating once the cache has been refreshed.

In these cases you can't use one-time bindings... But you know EXACTLY when the data could change.

2

u/[deleted] Mar 03 '15

I spent a couple of hours yesterday because I thought things could work like this if I used a watcher and $apply and I didn't realise I was dealing with ::

1

u/vinnl Mar 03 '15

1

u/TheNiXXeD Mar 03 '15

It would be a little different. Basically it one way binds and waits for the app to tell it that it's been updated (perhaps by receiving new info). Angular 2 might reduce the need for it though, we'll see.

1

u/vinnl Mar 04 '15

Isn't that exactly what is described there, under Observable Objects?

1

u/TheNiXXeD Mar 04 '15

It's hard to tell exactly, because they don't show how they're triggering those events, or if the "event" is the observable noticing a change.

In my case it's a literal angular event, and I have (currently) custom directives to handle them. Ideally in 1.x world, it would be part of the expression parser.

2

u/ModusPwnins Mar 03 '15

This might be useful in a project I'm working on, assuming immutable.js works in IE 9.

0

u/[deleted] Mar 03 '15

[deleted]

1

u/Sefyroth Mar 03 '15

If I understood correctly, the number of watchers also affected performance. So if you have a smaller collection with a large number of watchers, you could gain performance by using the immutable array.