No description or website provided.
JavaScript
Latest commit 7b2ea1f Sep 23, 2012 @frederickcook frederickcook bumped version
Permalink
Failed to load latest commit information.
.gitignore
README.md
index.js
package.json

README.md

mongoose-eventify

Mongoose plugin adding add, remove, and change events for attributes on Model class.

Install

Add the plugin as a dependency to your project in package.json:

{
  ...
  "dependencies": {
    "mongoose": ">=3.0.x",
    "mongoose-eventify": ">=0.0.1",
    ...
  },
  ...
}

Run npm install.

Example

// define our move schema and export our model
var MoveSchema = new Schema({
  date: {type: Date},
});
MoveSchema.plugin(require('mongoose-eventify'));
var Move = mongoose.model('Move', MoveSchema);
module.exports = exports = Move;


// now, in a different file, or wherever, we define some change events on the Model
Move.on('change:date', function(move) {
  console.log('Move ' + move._id + ' changed date to + ' move.date);
});

Move.on('add', function(move) {
  console.log('New move created');
});

Move.on('remove', function(move) {
  console.log('Move ' + move._id + ' has been cancelled');
});

Move.on('change', function(move) {
  console.log('Something changed in ' + move._id + '!!');
});

Credit

Inspired by mongoose-lifecycle Event syntax inspired by Backbone.js

License

MIT License