flatiron/resourceful — Issue #39: Document the hooks and events properly
Author: shinuza
Created: 2012-01-02 00:42:47+00:00
State: open

I've started to write a patch for this but I'm not sure if I caught all of the cases.

Hooks:

* create
* destroy
* filter
* find - also invoked when calling Resource.all()
* get
* save - also invoked when creating a Resource
* update
* view

Events:

* destroy
* error - fired when validate fails, or when before/after hooks calls their callback with a truthy first param
* filter
* find - also fired when calling all()
* get
* init - fired... IDK
* save - also fired on create()
* update
* view

Create is a tricky one:

``` js
Creature.on('error', function() {
console.log(arguments)
});

Creature.on('save', function() {
console.log('save')
});

Creature.before('create', function(instance, cb) {
console.log('before create');
cb();
});

Creature.after('create', function(err, instance, cb) {
console.log('after create');
cb();
});

Creature.before('save', function(instance, cb) {
console.log('before save');
cb();
});

Creature.after('save', function(err, instance, cb) {
console.log('after save');
cb();
});

Creature.create({diet: 'carnivore', vertebrate: true}, function() {
console.log('i am callback')
});

```

Should output

``` bash
before create
after create
before save
after save
save
i am callback
```

If the validation fails it should be

``` bash
before create
after create
error
i am callback
```

Am I missing something?