Skip to content

Instantly share code, notes, and snippets.

@jfsiii jfsiii/no_args.js
Created Oct 15, 2012

Embed
What would you like to do?
Issues with resourceful hooks
var resourceful = require('resourceful');
var resource = resourceful.define('resource');
// set handlers
resource.before('create', beforeCreate);
resource.after('create', afterCreate);
// kick it off
resource.create({name: 'Attempt 1'});
function beforeCreate(values, next) {
console.log('BEFORE', values);
values.altered = true;
next();
}
function afterCreate(err, created) {
if (err) throw err;
console.log('AFTER', created);
}
→ node no_args.js
BEFORE { id: null, resource: 'Resource', name: 'Attempt 1' }
AFTER { id: null, resource: 'Resource', name: 'Attempt 1' }
# ^ missing `altered` key
→ node two_args.js
BEFORE { id: null, resource: 'Resource', name: 'Attempt 1' }
# ^ `afterCreate` not called
var resourceful = require('resourceful');
var resource = resourceful.define('resource');
// set handlers
resource.before('create', beforeCreate);
resource.after('create', afterCreate);
// kick it off
resource.create({name: 'Attempt 1'});
function beforeCreate(values, next) {
console.log('BEFORE', values);
values.altered = true;
next(null, values);
}
function afterCreate(err, created) {
if (err) throw err;
console.log('AFTER', created);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.