Skip to content

Commit fde5fbb

Browse files
author
Maier, Martin
committed
issue#4:
* removed dependency to complete lodash library and added specific dependencies to lodash´s #clonedeep, #get and #set functions to get the library lighter
1 parent f81d517 commit fde5fbb

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

package-lock.json

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-immutable-helper",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"description": "Helpers for handling immutable objects with typescript",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -35,11 +35,12 @@
3535
},
3636
"homepage": "https://github.com/maimArt/typescript-immutable-helper#readme",
3737
"dependencies": {
38-
"lodash": "^4.17.10"
38+
"lodash.clonedeep": "^4.5.0",
39+
"lodash.get": "^4.4.2",
40+
"lodash.set": "^4.3.2"
3941
},
4042
"devDependencies": {
4143
"@types/chai": "^4.1.3",
42-
"@types/lodash": "^4.14.109",
4344
"@types/mocha": "^2.2.48",
4445
"@types/node": "^8.10.19",
4546
"chai": "^4.1.0",

src/replicator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import * as _ from 'lodash'
1+
import * as _cloneDeep from 'lodash.clonedeep'
2+
import * as _set from 'lodash.set'
3+
import * as _get from 'lodash.get'
24
import {deepFreeze, isDeepFrozen} from './deepFreeze'
35

46
/**
@@ -16,7 +18,7 @@ export class ReplicationBuilder<T> {
1618
* @param {RT} sourceObject traversing object
1719
*/
1820
private constructor(sourceObject: T) {
19-
this.replica = _.cloneDeep(sourceObject);
21+
this.replica = _cloneDeep(sourceObject);
2022
this.freeze = Object.isFrozen(sourceObject);
2123
if (this.freeze && !isDeepFrozen(sourceObject)) {
2224
console.warn('Source object is frozen but not deep frozen. Please care that always deepFreeze() is used to recursively freeze the object')
@@ -181,7 +183,7 @@ export class PropertyModifier<PT, VT> {
181183
* @returns {PT}
182184
*/
183185
with(value: VT): PT {
184-
_.set(this.replica, this.relativePathToRoot, value);
186+
_set(this.replica, this.relativePathToRoot, value);
185187
return this.parent
186188
}
187189

@@ -191,7 +193,7 @@ export class PropertyModifier<PT, VT> {
191193
* @returns PT this
192194
*/
193195
by(setFunction: (VT) => VT): PT {
194-
let currentvalue = _.get(this.replica, this.relativePathToRoot);
196+
let currentvalue = _get(this.replica, this.relativePathToRoot);
195197
let value = setFunction(currentvalue);
196198
return this.with(value)
197199
}
@@ -202,7 +204,7 @@ export class PropertyModifier<PT, VT> {
202204
* @returns {PT}
203205
*/
204206
withCloneAndDo(executeOnCloneFunction: (VT) => void): PT {
205-
let currentvalue = _.get(this.replica, this.relativePathToRoot);
207+
let currentvalue = _get(this.replica, this.relativePathToRoot);
206208
executeOnCloneFunction(currentvalue);
207209
return this.parent;
208210
}

src/tests/replicator.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ describe('ReplicationBuilder', () => {
112112
let durationinMS = new Date().getTime() - startTimestamp;
113113
console.info(repeatCount + ' clone repetitions with ' + objectCount + ' objects took ' + durationinMS + 'ms');
114114

115-
116115
expect(durationinMS).to.be.below(100)
117116
});
118117

119-
120118
});

0 commit comments

Comments
 (0)