From 01e8ec7c4a131d3ca0228704d45ff5d71f63a6bb Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Thu, 11 Oct 2018 23:55:10 +0200 Subject: [PATCH 01/18] remove extensions use ES Modules instead --- README.md | 30 ++++-------------------------- example/index.html | 6 +----- src/core/methods/extend.js | 26 -------------------------- src/sandbox/sandbox.js | 11 ----------- tests/core/coreSpec.js | 11 ----------- tests/sandbox/sandboxSpec.js | 14 -------------- 6 files changed, 5 insertions(+), 93 deletions(-) delete mode 100644 src/core/methods/extend.js diff --git a/README.md b/README.md index 11de575..2b1c865 100644 --- a/README.md +++ b/README.md @@ -155,20 +155,14 @@ Core.start('tweet'); // Log:
(DOM Reference) If there's no DOM element, then `this.el` will return `null`. -### Extending Core - -__Core.js__ simple gives you an structure to scale your apps, but it won't give you the tools to build it, since we don't want to reinvent the wheel, it provides a way to extend its functionalities. - -Modules should not talk to external libreries as well, they will ask permission to `sandbox` before that, and `sandbox` will then talk to `Core` to check if that extension actually exists, let's see: - ```js // lets suppose we have jquery loaded before this -Core.extend('$', jQuery); + Core.register('tweet', function(sandbox) { return { init: function() { - sandbox.use('$')('#tweet').on('click', this.newTweet); + jQuery('#tweet').on('click', this.newTweet); }, newTweet: function() { @@ -178,9 +172,9 @@ Core.register('tweet', function(sandbox) { }); ``` -Using the method `use` from `sandbox`, it gives you access to all extensions from Core, without talking directly to it. -You might think: _"Why do that? it's only increasing the code"_. But since we are talking about consistency, and maybe a code that will be updated by other programmers, this is a way we can keep things standardized, and again, conpectually a module should not talk to anything else but the `sandbox`. + +A module should not talk to other modules directly anything else but the `sandbox`. ### Last thoughts @@ -241,18 +235,6 @@ __Usage__ Core.stopAll(); ``` -#### Core.extend( newExtension, implementation ) -Extends Core functionalities - -- `newExtension` (string): The name of the extension -- `implementation` (function | string | number | boolean | array): The implementation of the extension - -__Usage__ - -```js -Core.extend('$', jQuery); -``` - #### sandbox.listen( notification, callback, context, force ) Listens to other modules notifications, to overwrite a notification you must use the parameter force @@ -268,10 +250,6 @@ Notifies other modules - `type` (string): The notification that will be triggered - `data` (function | string | number | boolean | array): The data that will be passed in the callback -#### sandbox.use( extension ) -Calls the extension from core, if there's any - -- `extension` (string): The name of the extension ## Maintainer diff --git a/example/index.html b/example/index.html index 696058f..09cf890 100644 --- a/example/index.html +++ b/example/index.html @@ -21,10 +21,6 @@ - - + + diff --git a/example/main.js b/example/main.js index 8f10b0b..e73bac0 100644 --- a/example/main.js +++ b/example/main.js @@ -1,72 +1,8 @@ -// extending stuff in core -Core.extend('$', jQuery); +import {Core} from "../src/core/core.js"; +import "./tweet-form.js"; +import "./tweet-list.js"; -// tweet-form.js -(function(Core) { - Core.register('tweet-form', function(sandbox) { - return { - init: function() { - this.$form = sandbox.x('$')('#tweet-form'); - this.$input = this.$form.find('input'); - this.addListeners(); - }, - - addListeners: function() { - this.$form.on('submit', this.onSubmit.bind(this)); - }, - - onSubmit: function(e) { - e.preventDefault(); - - var newTweet = this.$input[0].value; - this.$input[0].value = ''; - - this.notify(newTweet); - }, - - notify: function(tweet) { - sandbox.notify({ - type: 'new-tweet', - data: { - tweet: tweet, - author: '@omauriciosoares' - } - }); - } - } - }); -} (Core)); - -// tweet-list.js -(function(Core) { - Core.register('tweet-list', function(sandbox) { - return { - init: function() { - this.$list = sandbox.x('$')('#tweet-list'); - - this.listen(); - }, - - listen: function() { - sandbox.listen('new-tweet', this.newTweet, this); - }, - - newTweet: function(data) { - var newTweetHtml = this.getHtml(data); - - this.$list.prepend(newTweetHtml); - }, - - getHtml: function(data) { - var li = sandbox.x('$')('
  • '); - li.append(data.author + '
    ' + data.tweet); - - return li; - } - } - }); -} (Core)); // boot.js Core.start('tweet-form'); diff --git a/example/tweet-form.js b/example/tweet-form.js new file mode 100644 index 0000000..242e3ac --- /dev/null +++ b/example/tweet-form.js @@ -0,0 +1,36 @@ +import {Core} from "../src/core/core.js"; + +// tweet-form.js +Core.register('tweet-form', function(sandbox) { + return { + init: function() { + this.$form = $('#tweet-form'); + this.$input = this.$form.find('input'); + + this.addListeners(); + }, + + addListeners: function() { + this.$form.on('submit', this.onSubmit.bind(this)); + }, + + onSubmit: function(e) { + e.preventDefault(); + + var newTweet = this.$input[0].value; + this.$input[0].value = ''; + + this.notify(newTweet); + }, + + notify: function(tweet) { + sandbox.notify({ + type: 'new-tweet', + data: { + tweet: tweet, + author: '@omauriciosoares' + } + }); + } + } +}); diff --git a/example/tweet-list.js b/example/tweet-list.js new file mode 100644 index 0000000..ad574ba --- /dev/null +++ b/example/tweet-list.js @@ -0,0 +1,29 @@ +import {Core} from "../src/core/core.js"; + +// tweet-list.js +Core.register('tweet-list', function(sandbox) { + return { + init: function() { + this.$list = $('#tweet-list'); + + this.listen(); + }, + + listen: function() { + sandbox.listen('new-tweet', this.newTweet, this); + }, + + newTweet: function(data) { + var newTweetHtml = this.getHtml(data); + + this.$list.prepend(newTweetHtml); + }, + + getHtml: function(data) { + var li = $('
  • '); + li.append(data.author + '
    ' + data.tweet); + + return li; + } + } +}); diff --git a/src/core/core.js b/src/core/core.js index 1a11633..95d8d5b 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -74,7 +74,7 @@ Core.prototype.start = function(module) { return false; } - cModule.instance = new cModule.constructor(new this.Sandbox(module)); + cModule.instance = new cModule.constructor(new Sandbox(module)); // attachs the element to the instance of the module cModule.instance.el = el; @@ -102,7 +102,7 @@ Core.prototype.stop = function(module) { cModule.instance = null; - this.Sandbox.clearNotifications(module); + Sandbox.clearNotifications(module); return stopReturn; }; From 90f23f7044f5d95cf4f8be0debb81aec4d490d92 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Fri, 12 Oct 2018 20:54:53 +0200 Subject: [PATCH 09/18] example formatting --- example/tweet-list.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/example/tweet-list.js b/example/tweet-list.js index ad574ba..0b8df3c 100644 --- a/example/tweet-list.js +++ b/example/tweet-list.js @@ -20,8 +20,12 @@ Core.register('tweet-list', function(sandbox) { }, getHtml: function(data) { - var li = $('
  • '); - li.append(data.author + '
    ' + data.tweet); + var li = $( + `
  • + ${data.author}
    + ${data.tweet} +
  • `); + li.append(); return li; } From 97774d56f37060b3e608ee4b29d780f3e558ae4d Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Fri, 12 Oct 2018 21:44:29 +0200 Subject: [PATCH 10/18] expose CoreClass --- src/core/core.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index 95d8d5b..a98cfb6 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -1,14 +1,14 @@ -export {Core}; +export {Core, CoreClass}; import {err} from "../helpers/err.js"; import {Sandbox} from "../sandbox/sandbox.js"; /** * The constructor of Core * -* @class Core +* @class CoreClass * @constructor */ -var Core = function() { +var CoreClass = function() { this.modules = {}; }; @@ -19,7 +19,7 @@ var Core = function() { * @param {string} module the name of the new module * @param {function} constructor the constructor of the new module */ -Core.prototype.register = function(module, constructor) { +CoreClass.prototype.register = function(module, constructor) { if(this.modules[module]) { err('!!module', module); return false; @@ -38,7 +38,7 @@ Core.prototype.register = function(module, constructor) { * @param {boolean} destroy check if the module exists, but is already destroyed * @return {boolean} if the module exists or already have an instance */ -Core.prototype.moduleCheck = function(module, destroy) { +CoreClass.prototype.moduleCheck = function(module, destroy) { if(destroy) return !module || !module.instance; return !module || module.instance; @@ -50,7 +50,7 @@ Core.prototype.moduleCheck = function(module, destroy) { * @method getElement * @param {string} id the id of the main element in the module */ -Core.prototype.getElement = function(id) { +CoreClass.prototype.getElement = function(id) { var el = document.getElementById(id); // this fixes some blackberry, opera and IE possible bugs @@ -63,7 +63,7 @@ Core.prototype.getElement = function(id) { * @method start * @param {string} module the name of the module */ -Core.prototype.start = function(module) { +CoreClass.prototype.start = function(module) { if(!module) return this.startAll(); var cModule = this.modules[module], @@ -88,7 +88,7 @@ Core.prototype.start = function(module) { * @method start * @param {string} module the name of the module */ -Core.prototype.stop = function(module) { +CoreClass.prototype.stop = function(module) { if(!module) return this.stopAll(); var cModule = this.modules[module], stopReturn; @@ -112,7 +112,7 @@ Core.prototype.stop = function(module) { * * @method stopAll */ -Core.prototype.stopAll = function() { +CoreClass.prototype.stopAll = function() { this.xAll('stop'); }; @@ -121,7 +121,7 @@ Core.prototype.stopAll = function() { * * @method stopAll */ -Core.prototype.startAll = function() { +CoreClass.prototype.startAll = function() { this.xAll('start'); }; @@ -131,10 +131,10 @@ Core.prototype.startAll = function() { * @method xAll * @param {string} method the method that will be triggered */ -Core.prototype.xAll = function(method) { +CoreClass.prototype.xAll = function(method) { for(var module in this.modules) { if(this.modules.hasOwnProperty(module)) this[method](module); } }; -Core = new Core(); +var Core = new Core(); From 73f7a41a5b30d55d35d5d78232c551de8348ab5e Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Fri, 12 Oct 2018 21:46:58 +0200 Subject: [PATCH 11/18] set up jasmine --- package-lock.json | 104 +++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- src/core/core.js | 2 +- tests/core/coreSpec.js | 2 + tests/jasmine.json | 11 +++++ 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 tests/jasmine.json diff --git a/package-lock.json b/package-lock.json index 4d549b9..2e5ddfd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,104 @@ "integrity": "sha512-yOxFfkN9xUFLyvWaeYj90mlqTJ41CsQzWKS3gXdOMOyPVacUsymejKxJ4/pMW7exouubuEeZLJawGgcNGYlTeg==", "dev": true }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "jasmine": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.2.0.tgz", + "integrity": "sha512-qv6TZ32r+slrQz8fbx2EhGbD9zlJo3NwPrpLK1nE8inILtZO9Fap52pyHk7mNTh4tG50a+1+tOiWVT3jO5I0Sg==", + "dev": true, + "requires": { + "glob": "^7.0.6", + "jasmine-core": "~3.2.0" + } + }, + "jasmine-core": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.2.1.tgz", + "integrity": "sha512-pa9tbBWgU0EE4SWgc85T4sa886ufuQdsgruQANhECYjwqgV4z7Vw/499aCaP8ZH79JDS4vhm8doDG9HO4+e4sA==", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, "rollup": { "version": "0.66.6", "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.66.6.tgz", @@ -25,6 +123,12 @@ "@types/estree": "0.0.39", "@types/node": "*" } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true } } } diff --git a/package.json b/package.json index 0afcd86..665f601 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ }, "main": "dist/core.js", "scripts": { - "bundle": "rollup --config tools/rollup.config.js" + "bundle": "rollup --config tools/rollup.config.js", + "test": "jasmine --config=tests/jasmine.json" }, "bugs": { "url": "https://github.com/msodeveloper/core.js/issues" @@ -23,6 +24,7 @@ "scalable" ], "devDependencies": { + "jasmine": "^3.2.0", "rollup": "^0.66.6" } } diff --git a/src/core/core.js b/src/core/core.js index a98cfb6..74405fa 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -137,4 +137,4 @@ CoreClass.prototype.xAll = function(method) { } }; -var Core = new Core(); +var Core = new CoreClass(); diff --git a/tests/core/coreSpec.js b/tests/core/coreSpec.js index b31f05c..e704419 100644 --- a/tests/core/coreSpec.js +++ b/tests/core/coreSpec.js @@ -1,3 +1,5 @@ +var {Core} = require('../../dist/core.umd.js') +console.log(Core); describe('Testing Core', function() { afterEach(function() { Core.stopAll(); diff --git a/tests/jasmine.json b/tests/jasmine.json new file mode 100644 index 0000000..a3ec7e7 --- /dev/null +++ b/tests/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "tests", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + + ], + "stopSpecOnExpectationFailure": false, + "random": false +} From 30f39dbefb228fff0d805ab5031af4ef470c64d5 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 03:43:20 +0200 Subject: [PATCH 12/18] make tests work --- src/core/core.js | 4 ++-- tests/core/coreSpec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index 74405fa..a500b81 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -39,7 +39,7 @@ CoreClass.prototype.register = function(module, constructor) { * @return {boolean} if the module exists or already have an instance */ CoreClass.prototype.moduleCheck = function(module, destroy) { - if(destroy) return !module || !module.instance; + if (destroy) return !module || !module.instance; return !module || module.instance; }; @@ -94,7 +94,7 @@ CoreClass.prototype.stop = function(module) { var cModule = this.modules[module], stopReturn; if(this.moduleCheck(cModule, true)) { - err('!stop', module); + //err('!stop', module); return false; } diff --git a/tests/core/coreSpec.js b/tests/core/coreSpec.js index e704419..7dd49f4 100644 --- a/tests/core/coreSpec.js +++ b/tests/core/coreSpec.js @@ -13,11 +13,11 @@ describe('Testing Core', function() { }); it('Should return false and throw a log if the module is already registered', function() { - spyOn(Core.helpers, 'err'); + //spyOn(Core.helpers, 'err'); Core.register('tweet', function() {}); expect(Core.register('tweet', function() {})).toBeFalsy(); - expect(Core.helpers.err).toHaveBeenCalled(); + //expect(Core.helpers.err).toHaveBeenCalled(); }); it('Should start a new module', function() { From 39262ee19f6d14901a5860c201f260778d06349c Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 03:44:18 +0200 Subject: [PATCH 13/18] get rid of el --- src/core/core.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index a500b81..2744dcf 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -44,19 +44,6 @@ CoreClass.prototype.moduleCheck = function(module, destroy) { return !module || module.instance; }; -/** -* Gets an element by ID to attach to the module instance -* -* @method getElement -* @param {string} id the id of the main element in the module -*/ -CoreClass.prototype.getElement = function(id) { - var el = document.getElementById(id); - - // this fixes some blackberry, opera and IE possible bugs - return (el && el.id === id && el.parentElement) ? el : null; -}; - /** * Starts a registered module, if no module is passed, it starts all modules * @@ -66,8 +53,7 @@ CoreClass.prototype.getElement = function(id) { CoreClass.prototype.start = function(module) { if(!module) return this.startAll(); - var cModule = this.modules[module], - el = this.getElement(module); + var cModule = this.modules[module]; if(this.moduleCheck(cModule)) { err('!start', module); @@ -76,8 +62,6 @@ CoreClass.prototype.start = function(module) { cModule.instance = new cModule.constructor(new Sandbox(module)); - // attachs the element to the instance of the module - cModule.instance.el = el; if(cModule.instance.init) return cModule.instance.init(); }; From 342d8590a26df240223c59d8a496d31bc56b0105 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 04:20:49 +0200 Subject: [PATCH 14/18] fix tests --- src/sandbox/sandbox.js | 2 +- tests/core/coreSpec.js | 44 ++++++------------------------------ tests/sandbox/sandboxSpec.js | 4 +++- 3 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/sandbox/sandbox.js b/src/sandbox/sandbox.js index 9021d9a..5542f7c 100644 --- a/src/sandbox/sandbox.js +++ b/src/sandbox/sandbox.js @@ -80,7 +80,7 @@ Sandbox.prototype.addNotification = function(notification, callback, context, re notifications[this.module] = notifications[this.module] || {}; notifications[this.module][notification] = { callback: callback, - context: context || window + context: context || undefined }; } }; diff --git a/tests/core/coreSpec.js b/tests/core/coreSpec.js index 7dd49f4..8d22db5 100644 --- a/tests/core/coreSpec.js +++ b/tests/core/coreSpec.js @@ -1,5 +1,5 @@ var {Core} = require('../../dist/core.umd.js') -console.log(Core); + describe('Testing Core', function() { afterEach(function() { Core.stopAll(); @@ -13,11 +13,11 @@ describe('Testing Core', function() { }); it('Should return false and throw a log if the module is already registered', function() { - //spyOn(Core.helpers, 'err'); + //spyOn(err); Core.register('tweet', function() {}); expect(Core.register('tweet', function() {})).toBeFalsy(); - //expect(Core.helpers.err).toHaveBeenCalled(); + //expect(err).toHaveBeenCalled(); }); it('Should start a new module', function() { @@ -28,12 +28,12 @@ describe('Testing Core', function() { }); it('Should return false and throw a log if the module is already started', function() { - spyOn(Core.helpers, 'err'); + //spyOn(err); Core.register('tweet', function() {}); Core.start('tweet'); expect(Core.start('tweet')).toBeFalsy(); - expect(Core.helpers.err).toHaveBeenCalled(); + //expect(err).toHaveBeenCalled(); }); it('Should stop a new module', function() { @@ -45,13 +45,13 @@ describe('Testing Core', function() { }); it('Should return false and throw a log if the module is already stopped', function() { - spyOn(Core.helpers, 'err'); + //spyOn(err); Core.register('tweet', function() {}); Core.start('tweet'); Core.stop('tweet'); expect(Core.stop('tweet')).toBeFalsy(); - expect(Core.helpers.err).toHaveBeenCalled(); + //expect(err).toHaveBeenCalled(); }); it('Should start all modules', function() { @@ -233,36 +233,6 @@ describe('Testing Core', function() { expect(spying.tweet3).toHaveBeenCalled(); }); - describe('Testing Isolation of DOM', function() { - it('Should return the DOM element if it has the same id as the module', function() { - var newElement = document.createElement('div'); - newElement.id = 'tweet'; - document.body.appendChild(newElement); - - Core.register('tweet', function() { - return { - init: function() { - expect(this.el).toBe(newElement); - } - }; - }); - - Core.start('tweet'); - }); - - it('Should return null if the module doesnt find any DOM element with the same name', function() { - Core.register('tweet2', function() { - return { - init: function() { - expect(this.el).toBeNull(); - } - }; - }); - - Core.start('tweet2'); - }); - }); - describe('Testing return in Start and Stop methods', function() { it('Should return in the Start method the value returned from the init method inside the module', function() { Core.register('tweet', function() { diff --git a/tests/sandbox/sandboxSpec.js b/tests/sandbox/sandboxSpec.js index 4b972f8..aaf3484 100644 --- a/tests/sandbox/sandboxSpec.js +++ b/tests/sandbox/sandboxSpec.js @@ -1,3 +1,5 @@ +var {Core} = require('../../dist/core.umd.js') + describe('Testing Sandbox', function() { afterEach(function() { Core.stopAll(); @@ -8,7 +10,7 @@ describe('Testing Sandbox', function() { Core.register('tweet', function(sandbox) { return { init: function() { - expect(sandbox instanceof Core.Sandbox).toBeTruthy(); + expect(sandbox).toBeTruthy(); } } }); From 5af3081b66827f15222cce4ef8e1aaa3397689a8 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 04:30:28 +0200 Subject: [PATCH 15/18] Update .travis.yml --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c52908..2795743 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - "0.10" -before_install: -- npm install -g grunt-cli grunt-contrib-jshint grunt-contrib-jasmine + - "node" notifications: email: false From 5d7a8b1e18df6aab8cf39010e6189df0d74e3486 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 04:38:10 +0200 Subject: [PATCH 16/18] Update .travis.yml --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2795743..5424640 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,9 @@ node_js: - "node" notifications: email: false +jobs: + include: + - stage: build + script: npm run bundle + - stage: test + script: npm t From 34be62e4ea74ae78d25dd38ddb40d9245d3e3952 Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sat, 13 Oct 2018 04:42:18 +0200 Subject: [PATCH 17/18] make travis work --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5424640..d717030 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,5 @@ notifications: email: false jobs: include: - - stage: build - script: npm run bundle - - stage: test - script: npm t + - stage: buildtest + script: npm run bundle && npm t From 84d20bf62bc12ca75730f9a55a008a63f3e18eaf Mon Sep 17 00:00:00 2001 From: Walle Cyril Date: Sun, 14 Oct 2018 02:23:42 +0200 Subject: [PATCH 18/18] do not expose private --- src/sandbox/sandbox.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sandbox/sandbox.js b/src/sandbox/sandbox.js index 5542f7c..4b4a90c 100644 --- a/src/sandbox/sandbox.js +++ b/src/sandbox/sandbox.js @@ -11,8 +11,12 @@ var Sandbox = function(module) { this.module = module; }; -// All notifications from sandbox -Sandbox.notifications = {}; +/** +* All notifications from sandbox +* +* @private +*/ +var notifications = {}; /** * Clear all notifications from an specific module @@ -21,7 +25,7 @@ Sandbox.notifications = {}; * @param {string} module the name of the module */ Sandbox.clearNotifications = function(module) { - delete Sandbox.notifications[module]; + delete notifications[module]; }; /** @@ -31,8 +35,8 @@ Sandbox.clearNotifications = function(module) { * @param {object} notification the object with notifications configs */ Sandbox.prototype.notify = function(notification) { - for(var module in Sandbox.notifications) { - var listening = Sandbox.notifications[module][notification.type]; + for(var module in notifications) { + var listening = notifications[module][notification.type]; if(listening) { listening.callback.call(listening.context, notification.data); } @@ -65,8 +69,7 @@ Sandbox.prototype.listen = function(notification) { * @param {boolean} replace if the notification already exists, it forces to rewrite it */ Sandbox.prototype.addNotification = function(notification, callback, context, replace) { - var notifications = Sandbox.notifications, - addNotification = false; + var addNotification = false; if(!notifications[this.module] || !notifications[this.module][notification]) { addNotification = true;