AngularJS best approach: data driven or event driven? [closed] - angularjs

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
AngularJS is famous of the '3d': data binding, dependency injection and directives. As data binding is such a nature of angularJS application, I always assume data-driven is the best approach when making decision on how the app works.
For example, if I want to respond to some property updates, I will $watch on that property and write call back functions for it. And if I can use angularJS properly, there is no $apply required and the two way data binding will automatically do the magic with the great digest cycles.
However, in jQuery or many other JavaScript libraries, event-driven seems to be so common that people always think this is how client side should work. Event-driven approach in angularJS, on the other hand, means I need to $emit or $broadcast events across directives/controllers to throw events here and there. This is somehow different to the data-driven approach.
My idea is event-driven makes the whole application hard to debug, understand and maintain. The only reason I use it is because it's easy to pass data across scopes, when the nested scopes themselves are too complicated to do so.
Any idea on this? When should we stick to data-driven and when should we use event driven? What is the best approach in general?

Related

Why Angular(2~5) is way faster than AngularJS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
We all know AngularJS builds a digest loop when it comes to change detection , which proves to be less productive than Angular.
I want to know
How Angular works to get around this performance issue?
Does Angular also have a digest loop similar mechanism? if not , how does it know when a change could happen and need to perform change detection?
I know Angular boasts some features such as zone.js monkeypatch , unidirectional component tree, change detection strategy, RXJS ,immutableJS,etc.. either of which partly or directly drive Angular renders UI faster at the time a change happens. I'm not able to understand how Angular eventually gets faster by using these techniques together and properly?
Table that summarizes the major differences between Angular and AngularJS Change Detection.
To Explore more on this
Change Detection Differences between Angular and AngularJS
Change Detection Reinvented Victor Savkin
Angular’s $digest is reborn in the newer version of Angular
The Angular 2 Compiler Tobias Bosch
The Angular Compiler 4.0 - TOBIAS BOSCH.

What is the best way ( performance wise ) to animate numbers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In my angular.js app i'm using this directive:
https://github.com/sparkalow/angular-count-to
Which works great on the web.
When i compile it for phonegap, it's really really slow.
But what other way i have to animate a number from 0 to 200 (for example), in two secods, without hurting the performance of my app?
The directive uses $timeout, as is the suggested way to get setTimeout functionality in Angular. It's likely doing this for one of the following reasons, though there are others too:
Easy to inject a mock for testing
Assumes that each step should allow other components to update
It's the "Angular Way"
I don't believe #2 is actually a big concern since it doesn't expose the value or update anything on the scope anyway, and does standard HTML textContent manipulation.
Regardless, the point is that $timeout does a setTimeout as well as a $digest (allowing Angular to update other components). The extra digest cycles are likely the slow part, and every Angular developer should read up on them as they're central to Angular's design (hint: go read up on these now). As such, taking the original library, replacing the $timeout with a setTimeout call (and, optionally, a manual digest trigger when it finishes, in the if (step >= steps) block) should speed it up.
Be careful about these sorts of changes, though - $timeout is typically the correct way to go.

Are there any features that ReactJS possess, while AngularJS lacks? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I was playing with ReactJS for a bit, and given a bit of prior exposure to AngularJS, and the way things are done in the latter, I had a hard time to get used to the syntax and the 'flow' of React.
So I had the above-mentioned question, plus: are there scenarios when ReactJS should be preferred to AngularJS?
Could anyone point out what can be done [easier/better/more efficiently] in React rather than in Angular, and other way around.
It's actually the opposite. Angular has a lot of features, apis, configuration options, etc. React tries to be much simpler and let you choose how your application is structured. Controllers, directives, and templates are reduced to just components. Services are just plain JavaScript, there's nothing React specific about it. Things like $q and $timeout don't exist because there's no digress (use anything you like for those).
You use React in your application, vs making your application in angular.
ReactJS uses the concept of virtual DOM which speeds up the rendering of the app.
Watch Pete Hunt's excellent video on Virtual Dom here:
https://www.youtube.com/watch?v=-DX3vJiqxm4
The syntax might be very unconventional but the same thing can be said about Angular's concept of Directives, services, controllers, etc. It just takes time to get used to, but once you feel comfortable, you'll find that thinking in ReactJS really makes sense.

What is the use of custom directives in Angularjs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm newer to angularjs, it's difficult to understand the custom directive examples and the releated blogs.
why we use it and what is the usage of custom directives.(Using the built in directives is easy to understand and use)
It's possible to write our own custom directives based on our needs ?
what is the need of custom directives in angular js?
Directives could be used to increment the reusability of code.
Directives infact could be used to split the code of a complex app into more simple parts, reusable in others pages or projects.
Directives could be used to save the two way data binding, when AngularJS is used in conjunction with third party plugin.
Generally directives are used for DOM manipulation
Angular’s philosophy is modular development allowing us to write our front-end code with directives
I hope will helps you
Reusablity of code..... You can reuse your code at any Pages and anywhere in your projects.
solve the complex operations in this easily.
Reduce the amount of your code.Call it anywhere.
Handle your Dom easily.
Custom directives gives you the chance to define your own "web components", a very simple example would be a customize menu for your application, using custom directives you could write it once and use it in several applications.
Read more about it and you'll find it very useful (but completely optional as you might have enough with built in ones).
As an example, I find this link quite useful.

BackboneJS v/s CanJS which one is better? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm confused between the two choice which one to use BackboneJS/CanJS for my next project. Can anyone suggest which one is better ?
They have many similarities and differences, here are some:
Similarities
They both have models that can be observed, they use similar patterns for setting attributes
CanJS has Controls which in are quite similar to Views in Backbone, you listen to events in similar way in both
They are both small and very flexible
Routing in quite similar in both, Backbone has a special Router object while in CanJS you do the routing inside a Control class, but they are quite similar
I found that many of the patterns of doing things in Backbone are translatable to CanJS
Differences:
Backbone has a huge community, tons of plug-ins for doing about anything
You are likely to find more documentation and help when using Backbone
Backbone doesn't have a prescribed way of doing things e.g. rendering views. So this can be good or bad, depending on how you see it. Many time it leads to many projects doing things totally different when using Backbone.
Backbone doesn't implement view rendering or two way bindings, is up to you to implement that somehow
CanJS has reactive views using EJS or Mustache, so there is a defined way of doing this, it also has two way bindings
CanJS has components
CanJS is quite good at avoiding memory leaks, if you follow certain patterns, for example if you are listening for a window resize event inside a control, when you remove the control from the DOM CanJS will also remove the listeners automatically, in Backbone you have to do more manual work

Resources