Monday 15 September 2014

javascript - What's the good practice to wrap some useful js libraries to angular modules? -



javascript - What's the good practice to wrap some useful js libraries to angular modules? -

there useful libraries want utilize in angularjs, e.g. jquery, underscore, underscore.string.

it might not thought utilize them straight in angular code(say, controllers, directives), because it's hard mock , test. want wrap them angular modules:

angularunderscore.js

define(['angular', 'underscore'], function(ng, _) { homecoming ng.module('3rd-libraries') .service('underscoreservice', function() { homecoming _; }); });

my questions are:

is utilize .service() define service? or mill or constant better? is utilize underscoreservice, or underscore plenty , better?

i believe question of scope. although disagree, think loading _underscore dependency of every tests suite fine. reason rule of thumb saying "static" operation - - generic algorithm used not application logic or info sensitive, should tested separately (or not @ in case of _underscope frameworks). this makes tests simpler write, more readable , maintainable , putting rare cases aside, these tests fail anyway if _underscore have new bug on sorting array. moreover, can't see benefitting (other mocking, addressed before) di of these algorithm.

however, if algorithm more complex , involves info logic dependency, introduce mill (or service, both singletons) encapsulating logic , making testable itself. far service vs mill (vs provider), there tons of answers out there, liked: this

javascript angularjs

No comments:

Post a Comment