lundi 8 février 2016

What better way to partitioning app?

What better way partitioning app, for building with webpack / browserify ?

1 variant - require function (array):

/**
 * app.js
 */
const MainCtrl = require("./controllers/mainCtrl.js")

const App = angular.module('App', []);
App.controller('MainCtrl', MainCtrl);

/**
 * mainCtrl.js
 */
module.exports = [
    '$scope',
    ($scope) => {
        // code ...
    }
]

2 variant - pass module name into constructor function:

/**
 * app.js
 */
const App = angular.module('App', []);

require("./controllers/mainCtrl.js")('App');

/**
 * mainCtrl.js
 */
module.exports = function (moduleName) {
    const App = angular.module(moduleName);

    App.controller('MainCtrl', [
        '$scope',
        ($scope) => {
            // code ...
        }
    ]);
};

3 variant - pass module into constructor function:

/**
 * app.js
 */
const App = angular.module('App', []);

require("./controllers/mainCtrl.js")(App);

/**
 * mainCtrl.js
 */
module.exports = function (App) {
    App.controller('MainCtrl', [
        '$scope',
        ($scope) => {
            // code ...
        }
    ]);
};




Aucun commentaire:

Enregistrer un commentaire