Skip to content

Commit

Permalink
issue#4:
Browse files Browse the repository at this point in the history
* removed dependency to complete lodash library and added specific dependencies to lodash´s #clonedeep, #get and #set functions to get the library lighter
  • Loading branch information
Maier, Martin committed Jul 17, 2018
1 parent f81d517 commit fde5fbb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
26 changes: 15 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions src/replicator.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand All @@ -16,7 +18,7 @@ export class ReplicationBuilder<T> {
* @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')
Expand Down Expand Up @@ -181,7 +183,7 @@ export class PropertyModifier<PT, VT> {
* @returns {PT}
*/
with(value: VT): PT {
_.set(this.replica, this.relativePathToRoot, value);
_set(this.replica, this.relativePathToRoot, value);
return this.parent
}

Expand All @@ -191,7 +193,7 @@ export class PropertyModifier<PT, VT> {
* @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)
}
Expand All @@ -202,7 +204,7 @@ export class PropertyModifier<PT, VT> {
* @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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/tests/replicator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});


});

0 comments on commit fde5fbb

Please sign in to comment.