Issues with resourceful hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
→ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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