Socket
Socket
Sign inDemoInstall

delegates

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.1.0

5

History.md
0.1.0 / 2014-10-17
==================
* adds `.fluent()` to api
0.0.3 / 2014-01-13

@@ -3,0 +8,0 @@ ==================

28

index.js

@@ -23,2 +23,3 @@

this.setters = [];
this.fluents = [];
}

@@ -96,2 +97,27 @@

return this;
};
};
/**
* Delegator fluent accessor
*
* @param {String} name
* @return {Delegator} self
* @api public
*/
Delegator.prototype.fluent = function (name) {
var proto = this.proto;
var target = this.target;
this.fluents.push(name);
proto[name] = function(val){
if ('undefined' != typeof val) {
this[target][name] = val;
return this;
} else {
return this[target][name];
}
};
return this;
};

4

package.json
{
"name": "delegates",
"version": "0.0.3",
"version": "0.1.0",
"repository": "visionmedia/node-delegates",

@@ -13,2 +13,2 @@ "description": "delegate methods and accessors to another property",

"license": "MIT"
}
}

@@ -47,4 +47,49 @@

# API
## Delegate(proto, prop)
Creates a delegator instance used to configure using the `prop` on the given
`proto` object. (which is usually a prototype)
## Delegate#method(name)
Allows the given method `name` to be accessed on the host.
## Delegate#getter(name)
Creates a "getter" for the property with the given `name` on the delegated
object.
## Delegate#setter(name)
Creates a "setter" for the property with the given `name` on the delegated
object.
## Delegate#access(name)
Creates an "accessor" (ie: both getter *and* setter) for the property with the
given `name` on the delegated object.
## Delegate#fluent(name)
A unique type of "accessor" that works for a "fluent" API. When called as a
getter, the method returns the expected value. However, if the method is called
with a value, it will return itself so it can be chained. For example:
```js
delegate(proto, 'request')
.fluent('query')
// getter
var q = request.query();
// setter (chainable)
request
.query({ a: 1 })
.query({ b: 2 });
```
# License
MIT
MIT

@@ -78,2 +78,18 @@

})
})
})
describe('.fluent(name)', function () {
it('should delegate in a fluent fashion', function () {
var obj = {
settings: {
env: 'development'
}
};
delegate(obj, 'settings').fluent('env');
obj.env().should.equal('development');
obj.env('production').should.equal(obj);
obj.settings.env.should.equal('production');
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc