-
Notifications
You must be signed in to change notification settings - Fork 0
Adapters
Luis Eduardo Brito edited this page Sep 4, 2013
·
4 revisions
Custom classes specialized in transferring, connecting or converting framework data (for example, a model) are encapsulated by Adapters.
-
Model: used to structure data into schemas.
-
Response: used to pass data to HTTP requests as JSON.
-
Mongo: used to implement the model persistence in database.
An adapter don't require any special structure, you can implement them as a simple NodeJS Module and call them using the require()
method.
Although, we recommend a simple class structure to organize your stuff. Use the skeleton below to implement your adapters.
var myAdapterConfig = {
variable: "value"
}
var MyAdapter = function(config) {
// encapsulate the class
// public interface
var exports = {};
// implement a method
function sample_method(n) {
console.log("input: "+n);
};
// don't forget to append the function
// to the exports variable so it can
// be publicly visible
exports.sample_method = sample_method;
// class constructor
function init() {
// return the public interface
return exports;
}
// call the class constructor
return init()
}