nanoscope
Version:
A Lens Library for Javascript
99 lines (70 loc) • 2.77 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Setter.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: Setter.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
var _ = require('lodash'),
Lens = require('./Lens'),
Setter,
get;
/**
* Never allow `get` in a setter
*/
get = function () {
throw new Error('get not permitted in a Setter');
};
/**
* A `Setter` is a `Lens` that only supports setting and mapping. A `Setter` is constructed with a single function (`map`).
*
* @param {function} map Function that maps over the view of the Lens and returns the result.
* @param {object} options Additional flags to set in the Lens.
* @returns {Lens}
* @constructor
*/
Setter = function (map, options) {
var opts = { _setter: true};
if (_.isObject(options)) {
opts = _.extend(opts, options);
}
this.base = Lens;
this.base(get, map, opts);
};
Setter.prototype = new Lens;
/**
* Get a `Setter` from a `Lens`
*
* @param {Lens} lens The Lens to convert to a `Setter`
* @returns {Lens}
*/
Setter.fromLens = function (lens) {
return new Setter(lens._over, lens.getFlags());
};
module.exports = Setter;</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Compose.html">Compose</a></li><li><a href="Getter.html">Getter</a></li><li><a href="IndexedLens.html">IndexedLens</a></li><li><a href="IndexedLens.Unsafe.html">Unsafe</a></li><li><a href="Lens.html">Lens</a></li><li><a href="MultiLens.html">MultiLens</a></li><li><a href="Optional.html">Optional</a></li><li><a href="PathLens.html">PathLens</a></li><li><a href="PathLens.Unsafe.html">Unsafe</a></li><li><a href="Setter.html">Setter</a></li><li><a href="SliceLens.html">SliceLens</a></li></ul><h3>Global</h3><ul><li><a href="global.html#get">get</a></li><li><a href="global.html#IdLens">IdLens</a></li><li><a href="global.html#map">map</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha11</a> on Wed Dec 17 2014 09:18:53 GMT-0500 (EST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>