immutable-lens
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -1,36 +0,49 @@ | ||
import { setFieldValues } from './setFieldValues'; | ||
import { updateFields } from './updateFields'; | ||
import { pipe } from './pipe'; | ||
export class AbstractLens { | ||
update(updater) { | ||
return (source) => { | ||
const value = this.read(source); | ||
const newValue = updater(value); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var setFieldValues_1 = require("./setFieldValues"); | ||
var updateFields_1 = require("./updateFields"); | ||
var pipe_1 = require("./pipe"); | ||
var AbstractLens = /** @class */ (function () { | ||
function AbstractLens() { | ||
} | ||
AbstractLens.prototype.update = function (updater) { | ||
var _this = this; | ||
return function (source) { | ||
var value = _this.read(source); | ||
var newValue = updater(value); | ||
if (newValue === value) | ||
return source; | ||
return this.setValue(newValue)(source); | ||
return _this.setValue(newValue)(source); | ||
}; | ||
} | ||
setFieldValues(newValues) { | ||
return (source) => { | ||
const currentTarget = this.read(source); | ||
const updatedTarget = setFieldValues(currentTarget, newValues); | ||
}; | ||
AbstractLens.prototype.setFieldValues = function (newValues) { | ||
var _this = this; | ||
return function (source) { | ||
var currentTarget = _this.read(source); | ||
var updatedTarget = setFieldValues_1.setFieldValues(currentTarget, newValues); | ||
if (updatedTarget === currentTarget) | ||
return source; | ||
return this.setValue(updatedTarget)(source); | ||
return _this.setValue(updatedTarget)(source); | ||
}; | ||
} | ||
updateFields(updaters) { | ||
return (source) => { | ||
const currentTarget = this.read(source); | ||
const updatedTarget = updateFields(currentTarget, updaters); | ||
}; | ||
AbstractLens.prototype.updateFields = function (updaters) { | ||
var _this = this; | ||
return function (source) { | ||
var currentTarget = _this.read(source); | ||
var updatedTarget = updateFields_1.updateFields(currentTarget, updaters); | ||
if (updatedTarget === currentTarget) | ||
return source; | ||
return this.setValue(updatedTarget)(source); | ||
return _this.setValue(updatedTarget)(source); | ||
}; | ||
} | ||
pipe(...updaters) { | ||
return this.update(pipe(...updaters)); | ||
} | ||
} | ||
}; | ||
AbstractLens.prototype.pipe = function () { | ||
var updaters = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
updaters[_i] = arguments[_i]; | ||
} | ||
return this.update(pipe_1.pipe.apply(void 0, updaters)); | ||
}; | ||
return AbstractLens; | ||
}()); | ||
exports.AbstractLens = AbstractLens; | ||
//# sourceMappingURL=AbstractLens.js.map |
@@ -1,5 +0,8 @@ | ||
import { RootLens } from './RootLens'; | ||
export function createLens(instance) { | ||
return new RootLens(); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RootLens_1 = require("./RootLens"); | ||
function createLens(instance) { | ||
return new RootLens_1.RootLens(); | ||
} | ||
exports.createLens = createLens; | ||
//# sourceMappingURL=createLens.js.map |
@@ -1,22 +0,40 @@ | ||
import { AbstractLens } from './AbstractLens'; | ||
import { KeyFocusedLens } from './KeyFocusedLens'; | ||
import { IndexFocusedLens } from './IndexFocusedLens'; | ||
import { ThrowIfUndefinedLens } from './ThrowIfUndefinedLens'; | ||
export class DefaultValueLens extends AbstractLens { | ||
constructor(parentLens, defaultValue) { | ||
super(); | ||
this.parentLens = parentLens; | ||
this.defaultValue = defaultValue; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AbstractLens_1 = require("./AbstractLens"); | ||
var KeyFocusedLens_1 = require("./KeyFocusedLens"); | ||
var IndexFocusedLens_1 = require("./IndexFocusedLens"); | ||
var ThrowIfUndefinedLens_1 = require("./ThrowIfUndefinedLens"); | ||
var DefaultValueLens = /** @class */ (function (_super) { | ||
__extends(DefaultValueLens, _super); | ||
function DefaultValueLens(parentLens, defaultValue) { | ||
var _this = _super.call(this) || this; | ||
_this.parentLens = parentLens; | ||
_this.defaultValue = defaultValue; | ||
return _this; | ||
} | ||
get path() { | ||
return this.parentLens.path + '?.defaultTo(' + JSON.stringify(this.defaultValue) + ')'; | ||
} | ||
focusOn(key) { | ||
return new KeyFocusedLens(this, key); | ||
} | ||
focusIndex(index) { | ||
return new IndexFocusedLens(this, index); | ||
} | ||
read(source) { | ||
const value = this.parentLens.read(source); | ||
Object.defineProperty(DefaultValueLens.prototype, "path", { | ||
get: function () { | ||
return this.parentLens.path + '?.defaultTo(' + JSON.stringify(this.defaultValue) + ')'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
DefaultValueLens.prototype.focusOn = function (key) { | ||
return new KeyFocusedLens_1.KeyFocusedLens(this, key); | ||
}; | ||
DefaultValueLens.prototype.focusIndex = function (index) { | ||
return new IndexFocusedLens_1.IndexFocusedLens(this, index); | ||
}; | ||
DefaultValueLens.prototype.read = function (source) { | ||
var value = this.parentLens.read(source); | ||
if (value === undefined) | ||
@@ -26,13 +44,15 @@ return this.defaultValue; | ||
return value; | ||
} | ||
setValue(newValue) { | ||
}; | ||
DefaultValueLens.prototype.setValue = function (newValue) { | ||
return this.parentLens.setValue(newValue); | ||
} | ||
defaultTo(value) { | ||
}; | ||
DefaultValueLens.prototype.defaultTo = function (value) { | ||
return new DefaultValueLens(this.parentLens, value); | ||
} | ||
throwIfUndefined() { | ||
return new ThrowIfUndefinedLens(this); | ||
} | ||
} | ||
}; | ||
DefaultValueLens.prototype.throwIfUndefined = function () { | ||
return new ThrowIfUndefinedLens_1.ThrowIfUndefinedLens(this); | ||
}; | ||
return DefaultValueLens; | ||
}(AbstractLens_1.AbstractLens)); | ||
exports.DefaultValueLens = DefaultValueLens; | ||
//# sourceMappingURL=DefaultValueLens.js.map |
@@ -1,3 +0,7 @@ | ||
export { createLens } from './createLens'; | ||
export { pipe } from './pipe'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var createLens_1 = require("./createLens"); | ||
exports.createLens = createLens_1.createLens; | ||
var pipe_1 = require("./pipe"); | ||
exports.pipe = pipe_1.pipe; | ||
//# sourceMappingURL=index.js.map |
@@ -1,45 +0,66 @@ | ||
import { DefaultValueLens } from './DefaultValueLens'; | ||
import { AbstractLens } from './AbstractLens'; | ||
import { ThrowIfUndefinedLens } from './ThrowIfUndefinedLens'; | ||
export class IndexFocusedLens extends AbstractLens { | ||
constructor(parentLens, index) { | ||
super(); | ||
this.parentLens = parentLens; | ||
this.index = index; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DefaultValueLens_1 = require("./DefaultValueLens"); | ||
var AbstractLens_1 = require("./AbstractLens"); | ||
var ThrowIfUndefinedLens_1 = require("./ThrowIfUndefinedLens"); | ||
var IndexFocusedLens = /** @class */ (function (_super) { | ||
__extends(IndexFocusedLens, _super); | ||
function IndexFocusedLens(parentLens, index) { | ||
var _this = _super.call(this) || this; | ||
_this.parentLens = parentLens; | ||
_this.index = index; | ||
return _this; | ||
} | ||
get path() { | ||
return this.parentLens.path + `[${this.index}]`; | ||
} | ||
focusOn(key) { | ||
Object.defineProperty(IndexFocusedLens.prototype, "path", { | ||
get: function () { | ||
return this.parentLens.path + ("[" + this.index + "]"); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
IndexFocusedLens.prototype.focusOn = function (key) { | ||
throw Error('Can NOT focus on a property of a possibly undefined value'); | ||
} | ||
focusIndex(index) { | ||
}; | ||
IndexFocusedLens.prototype.focusIndex = function (index) { | ||
throw Error('Can NOT focus on an index of a possibly undefined value'); | ||
} | ||
read(source) { | ||
}; | ||
IndexFocusedLens.prototype.read = function (source) { | ||
return this.parentLens.read(source)[this.index]; | ||
} | ||
setValue(newValue) { | ||
return (source) => { | ||
const array = this.parentLens.read(source); | ||
if (array[this.index] === newValue) | ||
}; | ||
IndexFocusedLens.prototype.setValue = function (newValue) { | ||
var _this = this; | ||
return function (source) { | ||
var array = _this.parentLens.read(source); | ||
if (array[_this.index] === newValue) | ||
return source; | ||
const copy = [...array]; | ||
copy[this.index] = newValue; | ||
return this.parentLens.setValue(copy)(source); | ||
var copy = array.slice(); | ||
copy[_this.index] = newValue; | ||
return _this.parentLens.setValue(copy)(source); | ||
}; | ||
} | ||
setFieldValues(newValues) { | ||
}; | ||
IndexFocusedLens.prototype.setFieldValues = function (newValues) { | ||
throw Error('setFieldValues() can NOT be called on a Lens focused on a possibly undefined value. Try calling defaultTo() first.'); | ||
} | ||
updateFields(updaters) { | ||
}; | ||
IndexFocusedLens.prototype.updateFields = function (updaters) { | ||
throw Error('updateFields() can NOT be called on a Lens focused on a possibly undefined value. Try calling defaultTo() first.'); | ||
} | ||
defaultTo(value) { | ||
return new DefaultValueLens(this, value); | ||
} | ||
throwIfUndefined() { | ||
return new ThrowIfUndefinedLens(this); | ||
} | ||
} | ||
}; | ||
IndexFocusedLens.prototype.defaultTo = function (value) { | ||
return new DefaultValueLens_1.DefaultValueLens(this, value); | ||
}; | ||
IndexFocusedLens.prototype.throwIfUndefined = function () { | ||
return new ThrowIfUndefinedLens_1.ThrowIfUndefinedLens(this); | ||
}; | ||
return IndexFocusedLens; | ||
}(AbstractLens_1.AbstractLens)); | ||
exports.IndexFocusedLens = IndexFocusedLens; | ||
//# sourceMappingURL=IndexFocusedLens.js.map |
@@ -1,40 +0,69 @@ | ||
import { AbstractLens } from './AbstractLens'; | ||
import { DefaultValueLens } from './DefaultValueLens'; | ||
import { IndexFocusedLens } from './IndexFocusedLens'; | ||
import { ThrowIfUndefinedLens } from './ThrowIfUndefinedLens'; | ||
export class KeyFocusedLens extends AbstractLens { | ||
constructor(parentLens, key) { | ||
super(); | ||
this.parentLens = parentLens; | ||
this.key = key; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
get path() { | ||
return this.parentLens.path + '.' + this.key; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AbstractLens_1 = require("./AbstractLens"); | ||
var DefaultValueLens_1 = require("./DefaultValueLens"); | ||
var IndexFocusedLens_1 = require("./IndexFocusedLens"); | ||
var ThrowIfUndefinedLens_1 = require("./ThrowIfUndefinedLens"); | ||
var KeyFocusedLens = /** @class */ (function (_super) { | ||
__extends(KeyFocusedLens, _super); | ||
function KeyFocusedLens(parentLens, key) { | ||
var _this = _super.call(this) || this; | ||
_this.parentLens = parentLens; | ||
_this.key = key; | ||
return _this; | ||
} | ||
focusOn(key) { | ||
Object.defineProperty(KeyFocusedLens.prototype, "path", { | ||
get: function () { | ||
return this.parentLens.path + '.' + this.key; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
KeyFocusedLens.prototype.focusOn = function (key) { | ||
return new KeyFocusedLens(this, key); | ||
} | ||
focusIndex(index) { | ||
return new IndexFocusedLens(this, index); | ||
} | ||
read(source) { | ||
}; | ||
KeyFocusedLens.prototype.focusIndex = function (index) { | ||
return new IndexFocusedLens_1.IndexFocusedLens(this, index); | ||
}; | ||
KeyFocusedLens.prototype.read = function (source) { | ||
return this.parentLens.read(source)[this.key]; | ||
} | ||
setValue(newValue) { | ||
return (source) => { | ||
const parent = this.parentLens.read(source); | ||
if (parent[this.key] === newValue) | ||
}; | ||
KeyFocusedLens.prototype.setValue = function (newValue) { | ||
var _this = this; | ||
return function (source) { | ||
var parent = _this.parentLens.read(source); | ||
if (parent[_this.key] === newValue) | ||
return source; | ||
const parentCopy = Object.assign({}, parent); | ||
parentCopy[this.key] = newValue; | ||
return this.parentLens.setValue(parentCopy)(source); | ||
var parentCopy = __assign({}, parent); | ||
parentCopy[_this.key] = newValue; | ||
return _this.parentLens.setValue(parentCopy)(source); | ||
}; | ||
} | ||
defaultTo(value) { | ||
return new DefaultValueLens(this, value); | ||
} | ||
throwIfUndefined() { | ||
return new ThrowIfUndefinedLens(this); | ||
} | ||
} | ||
}; | ||
KeyFocusedLens.prototype.defaultTo = function (value) { | ||
return new DefaultValueLens_1.DefaultValueLens(this, value); | ||
}; | ||
KeyFocusedLens.prototype.throwIfUndefined = function () { | ||
return new ThrowIfUndefinedLens_1.ThrowIfUndefinedLens(this); | ||
}; | ||
return KeyFocusedLens; | ||
}(AbstractLens_1.AbstractLens)); | ||
exports.KeyFocusedLens = KeyFocusedLens; | ||
//# sourceMappingURL=KeyFocusedLens.js.map |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=Lens.js.map |
@@ -1,7 +0,14 @@ | ||
export function pipe(...updaters) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function pipe() { | ||
var updaters = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
updaters[_i] = arguments[_i]; | ||
} | ||
if (updaters.length === 0) | ||
return (something) => something; | ||
return function (something) { return something; }; | ||
else | ||
return (data) => updaters.reduce((previousValue, update) => update(previousValue), data); | ||
return function (data) { return updaters.reduce(function (previousValue, update) { return update(previousValue); }, data); }; | ||
} | ||
exports.pipe = pipe; | ||
//# sourceMappingURL=pipe.js.map |
@@ -1,43 +0,57 @@ | ||
import { KeyFocusedLens } from './KeyFocusedLens'; | ||
import { IndexFocusedLens } from './IndexFocusedLens'; | ||
import { updateFields } from './updateFields'; | ||
import { setFieldValues } from './setFieldValues'; | ||
import { pipe } from './pipe'; | ||
export class RootLens { | ||
get path() { | ||
return 'source'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var KeyFocusedLens_1 = require("./KeyFocusedLens"); | ||
var IndexFocusedLens_1 = require("./IndexFocusedLens"); | ||
var updateFields_1 = require("./updateFields"); | ||
var setFieldValues_1 = require("./setFieldValues"); | ||
var pipe_1 = require("./pipe"); | ||
var RootLens = /** @class */ (function () { | ||
function RootLens() { | ||
} | ||
focusOn(key) { | ||
return new KeyFocusedLens(this, key); | ||
} | ||
focusIndex(index) { | ||
return new IndexFocusedLens(this, index); | ||
} | ||
read(source) { | ||
Object.defineProperty(RootLens.prototype, "path", { | ||
get: function () { | ||
return 'source'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
RootLens.prototype.focusOn = function (key) { | ||
return new KeyFocusedLens_1.KeyFocusedLens(this, key); | ||
}; | ||
RootLens.prototype.focusIndex = function (index) { | ||
return new IndexFocusedLens_1.IndexFocusedLens(this, index); | ||
}; | ||
RootLens.prototype.read = function (source) { | ||
return source; | ||
} | ||
setValue(newValue) { | ||
return () => newValue; | ||
} | ||
update(updater) { | ||
}; | ||
RootLens.prototype.setValue = function (newValue) { | ||
return function () { return newValue; }; | ||
}; | ||
RootLens.prototype.update = function (updater) { | ||
return updater; | ||
} | ||
setFieldValues(newValues) { | ||
return (source) => setFieldValues(source, newValues); | ||
} | ||
updateFields(updaters) { | ||
return (source) => updateFields(source, updaters); | ||
} | ||
pipe(...updaters) { | ||
return pipe(...updaters); | ||
} | ||
}; | ||
RootLens.prototype.setFieldValues = function (newValues) { | ||
return function (source) { return setFieldValues_1.setFieldValues(source, newValues); }; | ||
}; | ||
RootLens.prototype.updateFields = function (updaters) { | ||
return function (source) { return updateFields_1.updateFields(source, updaters); }; | ||
}; | ||
RootLens.prototype.pipe = function () { | ||
var updaters = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
updaters[_i] = arguments[_i]; | ||
} | ||
return pipe_1.pipe.apply(void 0, updaters); | ||
}; | ||
// TODO Support optional types | ||
defaultTo(value) { | ||
RootLens.prototype.defaultTo = function (value) { | ||
throw Error('createLens() does NOT support optional types'); | ||
} | ||
}; | ||
// TODO Support optional types | ||
throwIfUndefined() { | ||
RootLens.prototype.throwIfUndefined = function () { | ||
throw Error('createLens() does NOT support optional types'); | ||
} | ||
} | ||
}; | ||
return RootLens; | ||
}()); | ||
exports.RootLens = RootLens; | ||
//# sourceMappingURL=RootLens.js.map |
@@ -1,2 +0,12 @@ | ||
export function setFieldValues(source, fieldValues) { | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function setFieldValues(source, fieldValues) { | ||
if (typeof fieldValues === 'function') | ||
@@ -6,8 +16,8 @@ throw Error('Lens.setFieldValues() does NOT accept functions as argument'); | ||
return source; | ||
const sourceObject = source; | ||
const newValues = fieldValues; | ||
const copy = Object.assign({}, sourceObject); | ||
let hasChanged = false; | ||
for (let key in newValues) { | ||
const newValue = newValues[key]; | ||
var sourceObject = source; | ||
var newValues = fieldValues; | ||
var copy = __assign({}, sourceObject); | ||
var hasChanged = false; | ||
for (var key in newValues) { | ||
var newValue = newValues[key]; | ||
if (newValue !== sourceObject[key]) { | ||
@@ -20,2 +30,3 @@ copy[key] = newValue; | ||
} | ||
exports.setFieldValues = setFieldValues; | ||
//# sourceMappingURL=setFieldValues.js.map |
@@ -1,21 +0,39 @@ | ||
import { AbstractLens } from './AbstractLens'; | ||
import { KeyFocusedLens } from './KeyFocusedLens'; | ||
import { IndexFocusedLens } from './IndexFocusedLens'; | ||
import { DefaultValueLens } from "./DefaultValueLens"; | ||
export class ThrowIfUndefinedLens extends AbstractLens { | ||
constructor(parentLens) { | ||
super(); | ||
this.parentLens = parentLens; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AbstractLens_1 = require("./AbstractLens"); | ||
var KeyFocusedLens_1 = require("./KeyFocusedLens"); | ||
var IndexFocusedLens_1 = require("./IndexFocusedLens"); | ||
var DefaultValueLens_1 = require("./DefaultValueLens"); | ||
var ThrowIfUndefinedLens = /** @class */ (function (_super) { | ||
__extends(ThrowIfUndefinedLens, _super); | ||
function ThrowIfUndefinedLens(parentLens) { | ||
var _this = _super.call(this) || this; | ||
_this.parentLens = parentLens; | ||
return _this; | ||
} | ||
get path() { | ||
return this.parentLens.path + '?.throwIfUndefined'; | ||
} | ||
focusOn(key) { | ||
return new KeyFocusedLens(this, key); | ||
} | ||
focusIndex(index) { | ||
return new IndexFocusedLens(this, index); | ||
} | ||
read(source) { | ||
const value = this.parentLens.read(source); | ||
Object.defineProperty(ThrowIfUndefinedLens.prototype, "path", { | ||
get: function () { | ||
return this.parentLens.path + '?.throwIfUndefined'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ThrowIfUndefinedLens.prototype.focusOn = function (key) { | ||
return new KeyFocusedLens_1.KeyFocusedLens(this, key); | ||
}; | ||
ThrowIfUndefinedLens.prototype.focusIndex = function (index) { | ||
return new IndexFocusedLens_1.IndexFocusedLens(this, index); | ||
}; | ||
ThrowIfUndefinedLens.prototype.read = function (source) { | ||
var value = this.parentLens.read(source); | ||
if (value === undefined) | ||
@@ -25,13 +43,15 @@ throw Error('Unable to read data: Undefined value'); | ||
return value; | ||
} | ||
setValue(newValue) { | ||
}; | ||
ThrowIfUndefinedLens.prototype.setValue = function (newValue) { | ||
return this.parentLens.setValue(newValue); | ||
} | ||
defaultTo(value) { | ||
return new DefaultValueLens(this.parentLens, value); | ||
} | ||
throwIfUndefined() { | ||
}; | ||
ThrowIfUndefinedLens.prototype.defaultTo = function (value) { | ||
return new DefaultValueLens_1.DefaultValueLens(this.parentLens, value); | ||
}; | ||
ThrowIfUndefinedLens.prototype.throwIfUndefined = function () { | ||
return this; | ||
} | ||
} | ||
}; | ||
return ThrowIfUndefinedLens; | ||
}(AbstractLens_1.AbstractLens)); | ||
exports.ThrowIfUndefinedLens = ThrowIfUndefinedLens; | ||
//# sourceMappingURL=ThrowIfUndefinedLens.js.map |
@@ -1,2 +0,12 @@ | ||
export function updateFields(source, fieldUpdaters) { | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function updateFields(source, fieldUpdaters) { | ||
if (typeof fieldUpdaters === 'function') | ||
@@ -6,9 +16,9 @@ throw Error('Lens.updateFields() does NOT accept functions as argument'); | ||
return source; | ||
const sourceObject = source; | ||
const updaters = fieldUpdaters; | ||
const shallowCopy = Object.assign({}, sourceObject); | ||
let hasChanged = false; | ||
for (let key in updaters) { | ||
const updater = updaters[key]; | ||
const newValue = updater(sourceObject[key]); | ||
var sourceObject = source; | ||
var updaters = fieldUpdaters; | ||
var shallowCopy = __assign({}, sourceObject); | ||
var hasChanged = false; | ||
for (var key in updaters) { | ||
var updater = updaters[key]; | ||
var newValue = updater(sourceObject[key]); | ||
if (newValue !== sourceObject[key]) { | ||
@@ -21,2 +31,3 @@ hasChanged = true; | ||
} | ||
exports.updateFields = updateFields; | ||
//# sourceMappingURL=updateFields.js.map |
{ | ||
"name": "immutable-lens", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Type-safe Lens API for immutable updates in complex data structures", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40011
558