Minulý týden byla vydána verze 1.0 JavaScriptového frameworku AngularJS, a protože je to jeden z kandidátů do front-end stacku našeho projektu, procházel jsem reakce. Tady jsou ty nejzajímavější, všechny z webu Hacker News (jinde jsou spíš jen gratulace k prvnímu releasu).
Uživatel doublerebel píše:
Well, Spine has fat controllers, and AngularJS has fat views. Whether I bind the data from the controller or the view it is the same amount of work. I don’t see the immediate advantage over other frameworks.
The “Reusable Components” section states “This lets you focus either on what the application does or how the application looks separately.” However, directly below is a view (template) stuffed in a controller as a string. AngularJS uses a “ng-” namespace for data whereas Knockout and others use the HTML5 “data-” spec. These seem like a step backwards, and behind what is found in Backbone, Spine, Ember, or Knockout.
Angular also includes its own forEach, JSON parsing, isArray, isElement, isFunction, isObject, isUndefined, noop and Promises methods (and more!). Other frameworks instead rely on existing, familiar libraries like jQuery or Underscore. It even has its own Uppercase and Lowercase methods, despite existing already in native JS. Even on the AngularJS website jQuery is included, therefore many of these methods unnecessarily exist twice.
Rather than use the existing event bindings, Angular has recreated them all with an “ng” prefix. Angular also has its own testing suite rather than integrating one of the existing popular JS test frameworks like Jasmine.
Angular doesn’t seem to have any serverside equivalent for its proprietary design, so creating a fallback for less rich clients will be difficult.
I am striving to understand the distinct advantage of AngularJS, however mostly what I see is just reinventing the wheel. With so many proprietary methods, the learning curve is steeper than using a popular framework like Spine which is already extensible with common modules. It is a good effort, but against its comparables it has catching up to do.
The template doesn’t have to be inlined as a string. It can be loaded from external file (html), or included within a
Having couple of util methods (forEach, isFunction, etc…), is just so that Angular can work without any other dependency, which many projects actually do. However you are free to use underscore, jquery and other libraries…
Jasmine ? Yep, we like it and we use it. Angular DOES use jasmine as its unit testing framework + we provide some helpers to make your life with jasmine + angular easier. But again, you can use any testing framework you like.
Angular is server agnostic. However, we have some ideas and plans how to do server side prerendering, so I believe it will come…
Zaujala mě poslední věta, jsem zvědav, co z toho bude.
Pak je tam dotaz a odpověď na vztah Angularu a Closure:
Q: This is indeed interesting! Any googler want to comment how is this different from its cousin Google Closure Library? It looks like it is leaner and more modern. Any other difference?
A: [Googler here]
There’s little overlap between Closure Library and Angular.
Closure Library is a grab bag library full of useful functions that you can pick and choose from and integrate into your own code. Kind of like a standard library.
Angular is a client-side MVC framework that gives you two-way databinding and custom views and dependency injection.
Indeed, in our angular project, we use both – Closure Library for useful functions and advanced compilations, and angular for MVC.
Komentář od uživatele hyuuu:
I have tried several javascript mvc frameworks: angular, backbone , javascriptmvc (i’m serious, the name is javascriptmvc) but time and time again I’m always drawn back to backbone, as this is a post about angular, one thing that turns me off about angular is the high lock in/dependency towards the framework.
They have a lot, I mean a lot of functionalities built in, but with that comfot comes the price if you want to use any other jquery/javascript library plugin that’s available out there. The only option you have is to “angularize” the plugin before you can use it. This is different from backbone, almost like the name suggest, it’s bare bone, there will be more boilerplate code but you get more freedom and most if not all the plugins that are available to you from your js libs can be used as is. My suggestion before going all out to ANY js framework, know how the application would behave beforehand.
Reakce je ve smyslu, že pro UI knihovny existují wrappery.
Na závěr jsem si nechal tento komentář, který je obecnější:
Does anyone else find it odd that most JavaScript frameworks end up solving half the easy problems of doing frontend heavy web development, and leave the other half unsolved?
Backbone goes so far as to encourage a menagerie of bizarrely constructed HTML strings getting injected into templates, Spine has superfat controllers instead utilizing models more prominently, and AngularJS solves the (relatively easy) problem of databinding and little else.
What the hell? This is why we have to use roll our own solution at my company using jQuery + BackBone + _.template.
Zatím nemůžu úplně soudit, ale přiznávám, že mě už v minulosti mnohokrát zaskočilo, kolik různých názvů se většinou vyjmenovává, když někdo popisuje, jak dělají JS frontend u nich. Většinou se jedná o nějakou kombinaci jQuery, jQuery UI, Backbone, Knockoutu, Underscore, Mustache a podobně, což mi připadá zvláštní, protože pro vývoj nad Flash Playerem má odpověď přesně čtyři písmena: Flex. Svět HTML je holt hodně jiný.
Zajimave, ze v ceskych koncinach je velmi malo znamy http://emberjs.com/, ktery se oddelil od Sproutcore, puvodniho frameworku na kterem bezel Apple MobileMe a bezi i dnesni iCloud. Ma za sebou nekolik let vyvoje, za kterym stoji slusny tym (lide z jQuery a RoR core teamu) a stale rostouci komunita.
mrknete na to co je v AngularJS udelano s jak http://builtwith.angularjs.org/ a zkuste si treba malickost jako je Sliding puzzle a uvidite zda to jinde pujde tak elegantne a jednoduse udelat.
Některý ty komentáře IMO vycházejí z nepochopení, jak to funguje. Pro mě je Angular no. 1 protože je lightweight a staví na principech, který považuju při vývoji za kruciální. Zatím jsme nenašel jinej JS framework s kompatibilním mentálním modelem. :)
Angular je HTML compiler. Je sexy, cool, a fajn, ale Closure je must have. Škoda, že Angular není napsanej v Closure. Vůbec ničemu by to nevadilo. Teď mne dobře poslouchejte. Pro vývoj rich JS aplikací potřebujete modely s událostmi, šablony a ui komponenty. I bez Angularu lze psát hezky, přehledně, a s testy.
Bylo by hrozně fajt, mít Angular HTML compiler v Closure, ale naprosto krásně se obejdu i bez něj.
A protože mobilní vývoj, kde je minimální množství kódu must have, neexistuje pro Closure alternativa.