Skip to content

Instantly share code, notes, and snippets.

@sgnl

sgnl/any-file.js Secret

Last active April 22, 2017 02:11
Show Gist options
  • Save sgnl/b17c4e8ac80349e23b9a to your computer and use it in GitHub Desktop.
Save sgnl/b17c4e8ac80349e23b9a to your computer and use it in GitHub Desktop.
Article Module Example
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: "..."});
const collection = [];
function all() {
return collection;
}
function add (params) {
// ...
}
module.exports = {
all: _all,
add: _add,
getByTitle: _getByTitle,
editByTitle: _editByTitle
};
@sgnl
Copy link
Author

sgnl commented Jul 15, 2016

Upgrade the code to utilize callback functions for extra awesomeness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment