-
-
Save sgnl/b17c4e8ac80349e23b9a to your computer and use it in GitHub Desktop.
Article Module Example
This file contains 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 Articles = require('db/articles.js'); | |
// returns the entire collection | |
Articles.all(); | |
// adds a new article to the collection | |
Articles.add({...}); | |
// returns the correct object from the collection | |
Articles.getByTitle('The%20Best%20Magpie%20Developer%20of%202016'); | |
// finds an article in the collection by its title, if found - updates the article based on object passed as the second parameter then returns `true` | |
// in the example below, it would change the title. | |
// if the article is not found, returns `false` | |
Articles.editByTitle('The%20Best%20Magpie%20Developer%20of%202016', { title: "..."}); |
This file contains 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
const collection = []; | |
function all() { | |
return collection; | |
} | |
function add (params) { | |
// ... | |
} | |
module.exports = { | |
all: _all, | |
add: _add, | |
getByTitle: _getByTitle, | |
editByTitle: _editByTitle | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upgrade the code to utilize callback functions for extra awesomeness