immutable-lens
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,2 @@ | ||
import { FieldLenses, FieldsUpdater, FieldUpdaters, FieldValues, Lens, Updater } from './Lens'; | ||
import { FieldLenses, FieldsUpdater, FieldUpdaters, FieldValues, Lens, UnfocusedLens, Updater } from './Lens'; | ||
export declare enum LensType { | ||
@@ -22,2 +22,3 @@ ROOT = 0, | ||
focusPath(...keys: any[]): any; | ||
focusIndex<Item>(this: UnfocusedLens<Item[]>, index: number): Lens<Item[], Item | undefined>; | ||
focusIndex<Item>(this: Lens<Source, Item[]>, index: number): Lens<Source, Item | undefined>; | ||
@@ -32,3 +33,3 @@ defaultTo<SafeTarget>(this: ImmutableLens<Source, ParentTarget, SafeTarget | undefined>, defaultValue: SafeTarget): Lens<Source, SafeTarget>; | ||
updatePartial(fieldsUpdater: FieldsUpdater<Target>): Updater<Source>; | ||
pipe(...updaters: Updater<Target>[]): Updater<Source>; | ||
pipe(...updaters: Array<Updater<Target>>): Updater<Source>; | ||
} |
@@ -51,3 +51,3 @@ "use strict"; | ||
var lens = this; | ||
keys.forEach(function (key) { return lens = lens.focusOn(key); }); | ||
keys.forEach(function (key) { return (lens = lens.focusOn(key)); }); | ||
return lens; | ||
@@ -68,3 +68,6 @@ }; | ||
if (this.type === LensType.THROW_IF_UNDEFINED) { | ||
return new ImmutableLens(this.path.slice(0, -'?.throwIfUndefined'.length) + '?.defaultTo(' + JSON.stringify(defaultValue) + ')', LensType.DEFAULT_VALUE, function (source) { return _this.readParentTargetFromSource(source); }, function (target) { return target || defaultValue; }, function (newValue) { return function () { return newValue; }; }, function (target) { return _this.setValue(target); }); | ||
return new ImmutableLens(this.path.slice(0, -'?.throwIfUndefined'.length) + | ||
'?.defaultTo(' + | ||
JSON.stringify(defaultValue) + | ||
')', LensType.DEFAULT_VALUE, function (source) { return _this.readParentTargetFromSource(source); }, function (target) { return target || defaultValue; }, function (newValue) { return function () { return newValue; }; }, function (target) { return _this.setValue(target); }); | ||
} | ||
@@ -179,3 +182,3 @@ return new ImmutableLens(this.path + '?.defaultTo(' + JSON.stringify(defaultValue) + ')', LensType.DEFAULT_VALUE, function (source) { return _this.read(source); }, function (target) { return target || defaultValue; }, function (newValue) { return function () { return newValue; }; }, function (target) { return _this.setValue(target); }); | ||
enumerable: false, | ||
configurable: true | ||
configurable: true, | ||
}); | ||
@@ -187,5 +190,3 @@ } | ||
var fieldUpdater = object[key]; | ||
return fieldUpdater.name === key | ||
? key | ||
: key + ': ' + fieldUpdater.name; | ||
return fieldUpdater.name === key ? key : key + ': ' + fieldUpdater.name; | ||
}) | ||
@@ -192,0 +193,0 @@ .join(', '); |
export interface NotAnArray { | ||
reduceRight?: 'NotAnArray'; | ||
} | ||
export interface Updater<T> { | ||
(value: T): T; | ||
} | ||
export declare type Updater<T> = (value: T) => T; | ||
export declare type FieldValues<T> = object & NotAnArray & Partial<T>; | ||
@@ -11,5 +9,3 @@ export declare type FieldUpdaters<T> = object & NotAnArray & { | ||
}; | ||
export interface FieldsUpdater<T> { | ||
(value: T): FieldValues<T>; | ||
} | ||
export declare type FieldsUpdater<T> = (value: T) => FieldValues<T>; | ||
export declare type FieldLenses<T, Composition> = object & NotAnArray & { | ||
@@ -21,2 +17,3 @@ [K in keyof Composition]: Lens<T, Composition[K]>; | ||
focus<NewTarget>(get: (value: Target) => NewTarget, set: (newValue: NewTarget) => Updater<Target>): Lens<Source, NewTarget>; | ||
focusIndex<Item>(this: UnfocusedLens<Item[]>, index: number): Lens<Item[], Item | undefined>; | ||
focusIndex<Item>(this: Lens<Source, Item[]>, index: number): Lens<Source, Item | undefined>; | ||
@@ -37,3 +34,3 @@ recompose<Composition>(this: Lens<Source, Target & object & NotAnArray>, fields: FieldLenses<Target, Composition>): Lens<Source, Composition>; | ||
updatePartial(this: Lens<Source, Target & NotAnArray>, fieldsUpdater: FieldsUpdater<Target>): Updater<Source>; | ||
pipe(...updaters: Updater<Target>[]): Updater<Source>; | ||
pipe(...updaters: Array<Updater<Target>>): Updater<Source>; | ||
defaultTo<SafeTarget extends Target>(this: Lens<Source, SafeTarget | undefined>, value: SafeTarget): Lens<Source, SafeTarget>; | ||
@@ -40,0 +37,0 @@ throwIfUndefined<SafeTarget extends Target>(this: Lens<Source, SafeTarget | undefined>): Lens<Source, SafeTarget>; |
import { Updater } from './Lens'; | ||
export declare function pipeUpdaters<T>(...updaters: Updater<T>[]): Updater<T>; | ||
export declare function pipeUpdaters<T>(...updaters: Array<Updater<T>>): Updater<T>; |
@@ -11,5 +11,7 @@ "use strict"; | ||
else | ||
return function (data) { return updaters.reduce(function (previousValue, update) { return update(previousValue); }, data); }; | ||
return function (data) { | ||
return updaters.reduce(function (previousValue, update) { return update(previousValue); }, data); | ||
}; | ||
} | ||
exports.pipeUpdaters = pipeUpdaters; | ||
//# sourceMappingURL=pipeUpdaters.js.map |
{ | ||
"name": "immutable-lens", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Type-safe Lens API for immutable updates in complex data structures", | ||
@@ -31,3 +31,4 @@ "keywords": [ | ||
"test-compilation-errors": "node ./testCompilationErrors.js", | ||
"tdd": "mocha --opts mocha.opts --watch" | ||
"tdd": "mocha --opts mocha.opts --watch", | ||
"lint": "tslint --project ./ --fix" | ||
}, | ||
@@ -40,13 +41,17 @@ "files": [ | ||
"devDependencies": { | ||
"@types/chai": "^4.0.8", | ||
"@types/mocha": "^2.2.44", | ||
"@types/chai": "^4.1.3", | ||
"@types/mocha": "^5.2.0", | ||
"chai": "^4.1.2", | ||
"chalk": "^2.3.0", | ||
"glob-promise": "^3.3.0", | ||
"mocha": "^4.0.1", | ||
"chalk": "^2.4.1", | ||
"glob-promise": "^3.4.0", | ||
"mocha": "^5.1.1", | ||
"prettier": "^1.12.1", | ||
"ramda": "^0.25.0", | ||
"shx": "^0.2.2", | ||
"ts-node": "^3.3.0", | ||
"typescript": "^2.6.2" | ||
"ts-node": "^6.0.3", | ||
"tslint": "^5.10.0", | ||
"tslint-config-prettier": "^1.12.0", | ||
"tslint-plugin-prettier": "^1.3.0", | ||
"typescript": "^2.8.3" | ||
} | ||
} |
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
36554
14