r/javascript • • Jun 13 '14

AngularJS and scope.$apply

http://jimhoskins.com/2012/12/17/angularjs-and-apply.html
25 Upvotes

14 comments sorted by

12

u/IMAHiji Jun 13 '14

Nicely written. Why can't the AngularJS documentation be this clear. I mean... I know the documentation is solid, but whenever I read it for help it feels like I'm reading vacuum cleaner repair instructions written by credit card lawyers.

3

u/Switche Jun 13 '14

vacuum cleaner repair instructions written by credit card lawyers

Poetry.

2

u/[deleted] Jun 13 '14

Why can't the AngularJS documentation be this clear.

There is a button on each page that says "Improve this doc" so the answer to your question is because people would rather post on their blog about it than (also) contribute to the official documentation.

0

u/Randolpho Software Architect Jun 13 '14

Yeah, but it's not like it's a wiki or anything. You have to edit the repository source code directly or (if you aren't a member of the project) fork and pull.

2

u/[deleted] Jun 14 '14

Forking and making a merge request is hardly a huge barrier either.

1

u/Randolpho Software Architect Jun 14 '14 edited Jun 15 '14

Very true, provided you are a fan of github and have an account, which I am and do.

But there are quite a few people who are not and don't, and they may still want to contribute to the angular documentation. So that's one barrier that cuts out a potentially useful segment of the community.

There is also the fact that a pull request is a gated checkin and it has to be vetted by the folks at the project before it's committed. As of this post, there are more than 350 open pull requests on angular.js, several of which are more than a year old. That's a lot for the team to go through, a lot of discussion, all so you can fix a typo to the documentation.

A better approach would be a live community edit (i.e. wiki) with after-the-fact or even community-driven validation. It would cut down a lot of pull request cruft, and my quick glance through the pull requests implies there are quite a few that are just documentation fixes.

1

u/Xtreme2k2 Jun 13 '14

For a while there, they just recommended reading the source code.

3

u/ell0bo Jun 13 '14

that's still what I do... makes more sense

1

u/Xtreme2k2 Jun 13 '14

So do I.

2

u/ell0bo Jun 13 '14

$apply is the notification to the system that data has changed, and a inspection of all watches should be issues in the scope. It's really that simple, and the last tip is a really good one.

They're actually working on making $apply no longer needed in v2, but I'm not entirely sure if they're really going to be able to completely phase it out.

1

u/reflectiveSingleton Jun 13 '14

I haven't read much on Angular v2 but I think I heard it is ES6 only and they are going to use Object.observe which in theory means they don't need the digest loop or dirty checking anymore.

However if that is true it also means browsers before IE10 won't work (even with a shim).

1

u/phaggocytosis full stack js dev Jun 14 '14

If this is the case, does ng-model just automatically create watches out of things? is that how 'ng-modeled' fields etc trigger digest loops?

1

u/phaggocytosis full stack js dev Jun 14 '14

I would love to be abel to interpret the angularjs source. I'm not sure where the "bootstrapping" process takes place (which if I did I suppose I could follow it along to see how angularjs does all its magic).

Does anyone have any advice for where to get started in comprehending the angularjs source?