From 74c05ae4319a3f1fe54f2d8fd4581e87ff8028da Mon Sep 17 00:00:00 2001 From: tomascorralcasas Date: Fri, 31 Mar 2017 05:54:58 +0200 Subject: [PATCH] Improve dependency injection in lib.js to: * Do not relay on jQuery so that it can be easily switched to use Zepto or another library with jQuery API compatible. * Do not load two times jQuery: * In lib.js * In each mainX.js file --- www/js/app/lib.js | 14 ++++++++------ www/js/app/main1.js | 2 +- www/js/app/main2.js | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/www/js/app/lib.js b/www/js/app/lib.js index f195555..6273642 100644 --- a/www/js/app/lib.js +++ b/www/js/app/lib.js @@ -1,7 +1,9 @@ -define(['jquery'], function ($) { - return { - getBody: function () { - return $('body'); - } - } +define(function(){ + return function ($) { + return { + getBody: function () { + return $('body'); + } + }; + }; }); diff --git a/www/js/app/main1.js b/www/js/app/main1.js index c5e54ee..6e55272 100644 --- a/www/js/app/main1.js +++ b/www/js/app/main1.js @@ -1,6 +1,6 @@ define(function (require) { var $ = require('jquery'), - lib = require('./lib'), + lib = require('./lib')($), controller = require('./controller/c1'), model = require('./model/m1'); diff --git a/www/js/app/main2.js b/www/js/app/main2.js index 35a60af..3cd6e71 100644 --- a/www/js/app/main2.js +++ b/www/js/app/main2.js @@ -1,6 +1,6 @@ define(function (require) { var $ = require('jquery'), - lib = require('./lib'), + lib = require('./lib')($), controller = require('./controller/c2'), model = require('./model/m2');