Skip to content

Commit

Permalink
* removed Extract constaint to avoid conflicts with minor typescript …
Browse files Browse the repository at this point in the history
…versions
  • Loading branch information
Maier, Martin committed Jun 19, 2018
1 parent 6d11acf commit e010d12
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"chai": "^4.1.0",
"mocha": "^5.2.0",
"ts-node": "^3.3.0",
"typescript": "^2.9.1"
"typescript": "^2.9.2"
}
}
44 changes: 22 additions & 22 deletions src/replicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {deepFreeze, isDeepFrozen} from './deepFreeze'
* Warns if source object is just frozen, not deep frozen
**/
export class ReplicationBuilder<T> {
private replica: T = null
private freeze = false
private replica: T = null;
private freeze = false;

/**
* default constructor
* @param {RT} sourceObject traversing object
*/
private constructor(sourceObject: T) {
this.replica = _.cloneDeep(sourceObject)
this.freeze = Object.isFrozen(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 All @@ -31,12 +31,12 @@ export class ReplicationBuilder<T> {
* @param {K} childNode of the root node
* @returns {ReplicaChildOperator<T, T[K]>} operator of child node
**/
public getChild<K extends Extract<keyof T, string>>(childNode: K): ReplicaChildOperator<T, T[K]> {
let node = this.replica[childNode]
public getChild<K extends keyof T>(childNode: K): ReplicaChildOperator<T, T[K]> {
let node = this.replica[childNode];
return new ReplicaChildOperator((() => this.build()), this.replica, node, childNode)
}

modify<K extends Extract<keyof T, string>>(childNode: K): PropertyModifier<ReplicationBuilder<T>, T[K]> {
modify<K extends keyof T>(childNode: K): PropertyModifier<ReplicationBuilder<T>, T[K]> {
return new PropertyModifier<ReplicationBuilder<T>, T[K]>(this, childNode, this.replica)
}

Expand Down Expand Up @@ -65,14 +65,14 @@ export class ReplicationBuilder<T> {
* Operator for nodes of the replica
*/
export class ReplicaChildOperator<RT, T> {
private buildFunction: () => RT
private node: T
private buildFunction: () => RT;
private node: T;
private replica: RT;
private relativePath;

constructor(buildFunction: () => RT, replica: RT, node: T, relativePath: string) {
this.buildFunction = buildFunction
this.node = node
constructor(buildFunction: () => RT, replica: RT, node: T, relativePath: string | number | symbol) {
this.buildFunction = buildFunction;
this.node = node;
this.replica = replica;
this.relativePath = relativePath;
}
Expand All @@ -82,7 +82,7 @@ export class ReplicaChildOperator<RT, T> {
* @returns {ReplicaChildOperator<RT, N[K]>} traversable child node
**/
getChild<K extends keyof T>(childNode: K): ReplicaChildOperator<RT, T[K]> {
let branch = this.node[childNode]
let branch = this.node[childNode];
return new ReplicaChildOperator(this.buildFunction, this.replica, branch, this.relativePath + '.' + childNode)
}

Expand All @@ -108,13 +108,13 @@ export class ReplicaChildOperator<RT, T> {
}

export class PropertyModifier<PT, VT> {
private replica: any
private parent: PT
private relativePathToRoot: string
private replica: any;
private parent: PT;
private relativePathToRoot: string | number | symbol;

constructor(parent: PT, relativePathToRoot: string, rootObject: any) {
this.replica = rootObject
this.parent = parent
constructor(parent: PT, relativePathToRoot: string | number | symbol, rootObject: any) {
this.replica = rootObject;
this.parent = parent;
this.relativePathToRoot = relativePathToRoot
}

Expand All @@ -124,7 +124,7 @@ export class PropertyModifier<PT, VT> {
* @returns {PT}
*/
to(value: VT): PT {
_.set(this.replica, this.relativePathToRoot, value)
_.set(this.replica, this.relativePathToRoot, value);
return this.parent
}

Expand All @@ -134,8 +134,8 @@ export class PropertyModifier<PT, VT> {
* @returns PT this
*/
by(setFunction: (VT) => VT): PT {
let currentvalue = _.get(this.replica, this.relativePathToRoot)
let value = setFunction(currentvalue)
let currentvalue = _.get(this.replica, this.relativePathToRoot);
let value = setFunction(currentvalue);
return this.to(value)
}
}

0 comments on commit e010d12

Please sign in to comment.