Created
March 12, 2018 10:26
-
-
Save guimochila/07af2b30b0ca9ef55665c2b098969d7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as MainController from './MainController'; | |
MainController.addBook('Harry Potter'); | |
MainController.addBook('Crazy ducks'); | |
MainController.addBook('Zombie land'); | |
console.log(MainController.myBooks()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Private variable | |
var books = []; | |
// Private functions | |
// Sort the books in alphabetical order | |
function sortBooks() { | |
return books.sort((a, b) => (a > b ? 1 : -1)); | |
} | |
// Public functions | |
export function getBooks() { | |
var sortedBooks = sortBooks(); | |
return sortedBooks; | |
} | |
export function addBooks(book) { | |
books.push(book); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as BooksCtrl from './BooksController'; | |
// Public functions | |
export function addBook(book) { | |
BooksCtrl.addBooks(book); | |
console.log(`Book ${book} added.`); | |
} | |
export function myBooks() { | |
return BooksCtrl.getBooks(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BooksController = (function() { | |
// Private variable | |
var books = []; | |
// Private functions | |
// Sort the books in alphabetical order | |
function sortBooks() { | |
return books.sort((a, b) => (a > b ? 1 : -1)); | |
} | |
// Public functions | |
return { | |
getBooks: function() { | |
var sortedBooks = sortBooks(); | |
return sortedBooks; | |
}, | |
addBooks: function(book) { | |
books.push(book); | |
}, | |
}; | |
})(); | |
var MainController = (function(BooksCtrl) { | |
// Public functions | |
return { | |
addBook: function(book) { | |
BooksCtrl.addBooks(book); | |
console.log(`Book ${book} added.`); | |
}, | |
myBooks: function() { | |
return BooksCtrl.getBooks(); | |
}, | |
}; | |
})(BooksController); | |
console.log(BooksController); | |
MainController.addBook('Harry Potter'); | |
MainController.addBook('Crazy ducks'); | |
MainController.addBook('Zombie land'); | |
console.log(MainController.myBooks()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment