Skip to content

Commit

Permalink
Merge pull request #56 from mauriciosoares/ES-Modules
Browse files Browse the repository at this point in the history
Es modules
  • Loading branch information
GrosSacASac authored Oct 14, 2018
2 parents 0afa948 + 84d20bf commit 5416fe0
Show file tree
Hide file tree
Showing 26 changed files with 465 additions and 917 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
bin
dist/
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
node_js:
- "0.10"
before_install:
- npm install -g grunt-cli grunt-contrib-jshint grunt-contrib-jasmine
- "node"
notifications:
email: false
jobs:
include:
- stage: buildtest
script: npm run bundle && npm t
184 changes: 0 additions & 184 deletions Gruntfile.js

This file was deleted.

30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,14 @@ Core.start('tweet'); // Log: <div id="tweet"></div> (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() {
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading

0 comments on commit 5416fe0

Please sign in to comment.