Commit 186ef9d7 by Ben Drucker

Fix EventEmitter application to Resource

parent 5fed700a
...@@ -18,6 +18,8 @@ function ClearbitResource (data) { ...@@ -18,6 +18,8 @@ function ClearbitResource (data) {
} }
ClearbitResource.find = Promise.method(function (options) { ClearbitResource.find = Promise.method(function (options) {
options = options || /* istanbul ignore next */ {};
this.emit('preFind', options);
return this.client.request(_.extend({ return this.client.request(_.extend({
api: this._options.api, api: this._options.api,
path: this._options.template(options), path: this._options.template(options),
...@@ -43,18 +45,26 @@ function createErrors (name) { ...@@ -43,18 +45,26 @@ function createErrors (name) {
} }
exports.create = function (name, options) { exports.create = function (name, options) {
return function (client) {
var Resource = function () { var Resource = function () {
ClearbitResource.apply(this, arguments); ClearbitResource.apply(this, arguments);
}; };
_.extend(Resource, new EventEmitter(), ClearbitResource, createErrors(name), { _.extend(Resource, new EventEmitter(), EventEmitter.prototype, ClearbitResource, createErrors(name), {
_name: name, _name: name,
_options: _.extend(options, { _options: _.extend({}, options, {
template: _.template(options.path) template: _.template(options.path)
}), })
});
return _.extend(function (client) {
return _.extend(Resource, {
client: client client: client
}); });
}; },
{
on: function () {
Resource.on.apply(Resource, arguments);
return this;
}
});
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment