|
|
|
|
|
by illicium
4313 days ago
|
|
Directives and scopes may be somewhat tricky concepts but they are not "bug ridden." Do you want composability? Write a bunch of element directives and nest them -- it'll end up looking almost exactly like React's classes and components. The main difference is that in React you throw away MVC and replace with with a big ol' render() function that spits out "HTML" (well, a shadow-DOM version of it anyway) Scopes are just objects that use prototypal inheritance to
inherit from outer scopes. Create an new (isolated) scope in your directive to isolate data to that component and its subcomponents. Also, using AngularUI Router is essential. |
|
As for composability they did not seriously thought this through. One bug I found out, the one that got fixed, showed up for anone who created two directives with isolated scope and transclusion, one used in template of the other. Basically isolated scope of outer directive got transcluded into inner one instead scope outer in relation to outside directive.
Scopes suffer from the same flaws that with() statement in js suffers mainly that when you assign inside it will be assigned not where you at first expect (current leaf scope not the scope of closest controller). When you add to this the fact that humble ng-model assigns you have a huge hole that nearly all newbies fall into at least once.
Another gripe is that angular doesn't eat it's own dogfood. For example ng-required is not a directive. It's just attribute parsed internally by input directive.
AngularUI router is worthless if you need to have multiple tabs inside your web app as it allows you to have just one branch of views tree shown at any given time. There are suggestions about implementing parallel subviews but last time I checked it was too hard for them.
Angular is set of legos with lots of weird pieces. React is blueprint how to make your own bricks so they fit together and won't turn into tower of ugly chaos when assembled.
I was distrustful towards virtual dom at first. But that's just a way of batching and saving dom changes. The architecture that's enabled by it is all about composability and maintaining control over your project.