evanp/databank — Issue #19: pre-save, post-read hooks in DatabankObject
Author: evanp
Created: 2011-12-16 21:44:54+00:00
State: open

I'm finding myself writing code like this:

MyClass = DatabankObject.subClass('mytype');

MyClass.originalCreate = MyClass.create;

MyClass.create = function(properties, callback) {

if (!properties.someProperty) {
properties.someProperty = "a default value";
}

return MyClass.originalCreate(properties, callback);

};

It may make sense to use pre- and post-hooks to do this kind of work instead. So instead something like:

MyClass.preCreate = function(properties, next) {

if (!properties.someProperty) {
properties.someProperty = "a default value";
}

next(properties);
}

Continuation-passing style here allows querying the databank for components, etc.