Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perhaps use throttled $watch instead of addPollFn? #2

Closed
ajoslin opened this issue Jul 22, 2013 · 7 comments
Closed

Perhaps use throttled $watch instead of addPollFn? #2

ajoslin opened this issue Jul 22, 2013 · 7 comments

Comments

@ajoslin
Copy link

ajoslin commented Jul 22, 2013

I see why you used addPollFn instead of $rootScope.$watch; for many rapid actions you don't want to do a potentially huge compare every $digest.

But if I use this, I also don't want to have a potentially huge compare every 100ms, especially on things like android 2.x browser.

...so what if on every $digest, if there's no timeout, you set a new timeout to compare in 100ms?

@ajoslin
Copy link
Author

ajoslin commented Jul 22, 2013

Something like:

$rootScope.$watch(onDigest);

var compareTimeout;
function onDigest() {
  if (!compareTimeout) {
    compareTimeout = setTimeout(compare, 100);
  }
}

function compare() {
  compareTimeout = null;
  //do compare and set to localStorage if dirty
}

@gsklee
Copy link
Owner

gsklee commented Jul 23, 2013

Sounds nice, lazy binding / dirty check debouncing is actually something on the todo list. Care to send in a PR?

@gsklee
Copy link
Owner

gsklee commented Aug 13, 2013

@ajoslin Any progress on this?

@ajoslin
Copy link
Author

ajoslin commented Aug 13, 2013

No, forgot to reply sorry :-)

Don't have time atm.

On Tue, Aug 13, 2013 at 3:06 AM, Gias Kay Lee notifications@github.comwrote:

@ajoslin https://github.com/ajoslin Any progress on this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-22546804
.

@tilgovi
Copy link

tilgovi commented Sep 17, 2013

The compare should never be huge. angular.equals should short circuit very quickly as soon as it reads the first key not starting with $, since it will never be found on the old storage object (it is cleared of all user keys after each pass).

@tilgovi
Copy link

tilgovi commented Sep 17, 2013

For this reason I would actually advocate for a rootscope watcher. The comparisons should be lightning fast. The debounce itself is a comparison ("is a timer already set?"). I think you're both overthinking this. The check for whether an update is needed (angular.equals) is a handful of comparisons but it'd guess that if angular is using it internally in watcher code it's likely JIT'ted fast-path.

Maybe it makes sense to add the $ attributes to $storage, but make it an array? Then the check could just be a direct .length comparison.

@gsklee gsklee closed this as completed in 6982626 Oct 15, 2013
egilkh added a commit that referenced this issue May 13, 2015
@azachar
Copy link

azachar commented Oct 3, 2016

Hi there,
I am having a problem with protractor tests using this approach, have a look at #246. Do you have an idea why it is happening?

Cheers,
Andrej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants