javascript - AngularJS modules vs CommonJS/ECMA6 modules -


i've joined ongoing web project frontend written in angular 1 mvc framework , using webpack build system , i'm feeling neo in matrix 2 in stack of nested matrices.

the project split separate .js files, each annotated module in either commonjs style (with require , module.exports) or ecma6 style (with imports , exports). webpack transpiles ecma6 ecma5 babel , creates single bundle them.

within commonjs modules reside angularjs modules. living inside commonjs, angular task of dependency injection of own angular's requirejs-esque module system.

i'm feeling same job of dependency management done twice.

is true, when angular written, angular developers had in mind multi-module angular projects should've been concatenated e.g. grunt concat single bundle , served client, angular $injector responsible dependency management? so, our webpack build over-complication on top of that?


example project:

file model.module.js:

import angular "angular";  import {entityviewcontroller} './entity_view_controller'  // @nginject function routes($stateprovider) {     $stateprovider.state("modeller.entity.view", {         url: "/:id/view",         controller: entityviewcontroller,         templateurl: "/states/modeller/model/entity_view.html"     }); }  export default angular.module("states.modeller.entity", [])     .config(routes)     .controller("entityviewcontroller", entityviewcontroller); 

file entity_view_controller.js:

"use strict"  export /* nginject */ function entityviewcontroller($scope, $stateparams, entitymodel) {     $scope.entity = {};     $scope.attributes = [];     entitymodel.get({id: $stateparams.id}, (data) => {         $scope.entity = data.entity;         $scope.attributes = data.attributes;     }); } 

it true angular concat-friendly , doesn't require other modular solutions. development styles (notably jp) imply usage of iife's avoid global namespace pollution. 1 can write iife's hand or delegate job webpack or other modular systems.

the usage of modular systems introduces design solutions unsuitable plain js.

class inheritance in angular components (e.g. controllers) ugly angular di. , when using classes app-wide iife modules 1 may need maintain exports manually - again, that's job modular systems.

considerable amount of app components can framework agnostic, expands options architectural decisions (framework migration, isomorphic apps) , allows units tested separately framework.

js modules , angular modules/di play nicely in experience.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -