Experimenting node.js.
Extended Object and Array a bit.
Add properties of from object to current object. If same property exists, then replace if replace is true. Default true.
Return a new object with subset of properties of current object.
Merge ary into current array.
A context object is added to each request. It is used for template rendering.
Context object handles flash messages. Flash message is a kind of message that generated on business logic layer, supposed to be displayed to user once, and only once. It needs to handle case of redirect. Here we use session object to persist messages util they are renderred once.
Currently two type: error, info.
Add error message[s]. msg can be string or array of strings. If no msg supplied then return all errors.
Add info message[s]. msg can be string or array of strings. If no msg supplied then return all info messages.
Clear flash messages from session.
The first goal is to implemente Active Record pattern talk to MongoDB.
Models are defined unser models/ directory. To use:
var Contact = require('../models').Contact;
var contact = new Contact();
...
contact.bind(data);
contact.save(caller, callback);
...
Each model only need to define FIELD_MAP to have basic methods
- validate
- bind
- find
- save
- delete
Example:
module.exports.name = 'Contact';
module.exports.klass = function(data) {
this.collection_name = 'contact';
this.FIELDMAP = {
name: {default: '', type: 'string', required: true},
owner_id: {default: '', type: 'ObjectId', required: true},
primary_contact_type: {default: '', type: 'string', required: true}, // email|phone|skype
primary_contact: {default: '', type: 'string', required: true},
created_on: {default: new Date(), type: 'datetime'},
modified_on: {default: new Date(), type: 'datetime'}
}
if (this.init) {
this.init(data);
}
}
Not finished yet...