git submodules - how to create an environment agnostic javascript library -
i'm creating javascript library, , want environment agnostic (it not use dom, ajax, or nodejs api. vanilla javascript). so, it's supposed run in javascript environment (browsers, npm, meteor smart packages, v8 c bindings...).
my approach creating git repo library, library inside single global variable, without thinking patterns commonjs or amd. later, i'll create git repo, using library git submodule, , create needed release npm module. i'm concerned if it's approach, didn't found doing way. pros: code vanilla javascript, without awareness of environment patterns. not bind commonjs. repackable (copy , paste or git submodule) javascript environment. small needed sent browsers. cons: i'll have maintain many git environments want support. @ least second git repo deliver on npm.
taking jquery example, runs in both browser , nodejs, 1 git repo. there code aware of "exports" variable run on nodejs or other commonjs compatible enviroment. pros: 1 git repo mantain. cons: binded commonjs pattern (to achieve npm compatibility)
my question is: following correct (or acceptable) approach? or should follow jquery's path, , try create single git repo?
update 1:
browserify , other require()
libraries not valid answers. question not how use require()
on browser, instead, it's architecture pattern achieve enviroment agnosticism.
update 2:
create browser/nodejs module is not question, it's known. question is: can make real enviroment agnostic library? example binded commonjs pattern, used in nodejs.
if looking design recommendation future library work in opinion can think-future , use usual object oriented practices proven in other languages, systems , libraries.
mainly concentrate on uml view of design.
forget "one variable" requirement.
use features proposed in planned next version of javascript.
- http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes
- http://wiki.ecmascript.org/doku.php?id=harmony:modules_rationale
there experimental compiler available allows write es6-style code today (see https://www.npmjs.org/package/es6-module-transpiler-rewrite).
node.js has --harmony
command line switch allows same (see what `node --harmony` do?)
so in opinion correct approach follow best practices , "think future"
Comments
Post a Comment