From fde5fbb2271107b298db95a15514d569c3205f05 Mon Sep 17 00:00:00 2001 From: "Maier, Martin" Date: Tue, 17 Jul 2018 10:44:01 +0200 Subject: [PATCH] =?UTF-8?q?issue#4:=20*=20removed=20dependency=20to=20comp?= =?UTF-8?q?lete=20lodash=20library=20and=20added=20specific=20dependencies?= =?UTF-8?q?=20to=20lodash=C2=B4s=20#clonedeep,=20#get=20and=20#set=20funct?= =?UTF-8?q?ions=20to=20get=20the=20library=20lighter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 26 +++++++++++++++----------- package.json | 7 ++++--- src/replicator.ts | 12 +++++++----- src/tests/replicator.spec.ts | 2 -- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5491a27..f31eb47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "typescript-immutable-helper", - "version": "0.4.0", + "version": "0.6.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -10,12 +10,6 @@ "integrity": "sha512-f5dXGzOJycyzSMdaXVhiBhauL4dYydXwVpavfQ1mVCaGjR56a9QfklXObUxlIY9bGTmCPHEEZ04I16BZ/8w5ww==", "dev": true }, - "@types/lodash": { - "version": "4.14.109", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.109.tgz", - "integrity": "sha512-hop8SdPUEzbcJm6aTsmuwjIYQo1tqLseKCM+s2bBqTU2gErwI4fE+aqUVOlscPSQbKHKgtMMPoC+h4AIGOJYvw==", - "dev": true - }, "@types/mocha": { "version": "2.2.48", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz", @@ -222,10 +216,20 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, - "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + }, + "lodash.set": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz", + "integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=" }, "make-error": { "version": "1.3.0", diff --git a/package.json b/package.json index 0884866..88e1068 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-immutable-helper", - "version": "0.6.2", + "version": "0.6.3", "description": "Helpers for handling immutable objects with typescript", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -35,11 +35,12 @@ }, "homepage": "https://github.com/maimArt/typescript-immutable-helper#readme", "dependencies": { - "lodash": "^4.17.10" + "lodash.clonedeep": "^4.5.0", + "lodash.get": "^4.4.2", + "lodash.set": "^4.3.2" }, "devDependencies": { "@types/chai": "^4.1.3", - "@types/lodash": "^4.14.109", "@types/mocha": "^2.2.48", "@types/node": "^8.10.19", "chai": "^4.1.0", diff --git a/src/replicator.ts b/src/replicator.ts index 264eda7..7edc1f2 100644 --- a/src/replicator.ts +++ b/src/replicator.ts @@ -1,4 +1,6 @@ -import * as _ from 'lodash' +import * as _cloneDeep from 'lodash.clonedeep' +import * as _set from 'lodash.set' +import * as _get from 'lodash.get' import {deepFreeze, isDeepFrozen} from './deepFreeze' /** @@ -16,7 +18,7 @@ export class ReplicationBuilder { * @param {RT} sourceObject traversing object */ private constructor(sourceObject: T) { - this.replica = _.cloneDeep(sourceObject); + this.replica = _cloneDeep(sourceObject); this.freeze = Object.isFrozen(sourceObject); if (this.freeze && !isDeepFrozen(sourceObject)) { 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 { * @returns {PT} */ with(value: VT): PT { - _.set(this.replica, this.relativePathToRoot, value); + _set(this.replica, this.relativePathToRoot, value); return this.parent } @@ -191,7 +193,7 @@ export class PropertyModifier { * @returns PT this */ by(setFunction: (VT) => VT): PT { - let currentvalue = _.get(this.replica, this.relativePathToRoot); + let currentvalue = _get(this.replica, this.relativePathToRoot); let value = setFunction(currentvalue); return this.with(value) } @@ -202,7 +204,7 @@ export class PropertyModifier { * @returns {PT} */ withCloneAndDo(executeOnCloneFunction: (VT) => void): PT { - let currentvalue = _.get(this.replica, this.relativePathToRoot); + let currentvalue = _get(this.replica, this.relativePathToRoot); executeOnCloneFunction(currentvalue); return this.parent; } diff --git a/src/tests/replicator.spec.ts b/src/tests/replicator.spec.ts index 3ee9434..8e5d55c 100644 --- a/src/tests/replicator.spec.ts +++ b/src/tests/replicator.spec.ts @@ -112,9 +112,7 @@ describe('ReplicationBuilder', () => { let durationinMS = new Date().getTime() - startTimestamp; console.info(repeatCount + ' clone repetitions with ' + objectCount + ' objects took ' + durationinMS + 'ms'); - expect(durationinMS).to.be.below(100) }); - });