Skip to content

Commit 80389ef

Browse files
authored
Merge pull request #43 from haseebrabbani/disable-diff-tracking-per-object
disable diff tracking per object
2 parents e6988e4 + 00e0a4e commit 80389ef

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
},
5959
"dependencies": {
6060
"@types/debug": "^4.1.5",
61+
"@types/lodash": "^4.14.165",
6162
"@types/n3": "^1.1.1",
6263
"@xanthous/n3": "^1.3.5",
6364
"class-validator": "^0.10.2",

src/transaction/diff-tracker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { get } from 'lodash';
12
import { IObjectLiteral } from '../utils/type';
23

34
export class DiffTracker {
@@ -33,7 +34,7 @@ export class DiffTracker {
3334
enumerable: true,
3435
set: function(value: any) {
3536
tracker.ensureInstance(target, propertyName, diffKey || propertyName);
36-
tracker._instances.get(target)![propertyName].set(value);
37+
tracker._instances.get(target)![propertyName].set(value, get(target, 'trackChanges'));
3738
},
3839
get: function() {
3940
tracker.ensureInstance(target, propertyName, diffKey || propertyName);
@@ -149,8 +150,8 @@ export class DiffValue<T> {
149150
this._dirty = false;
150151
}
151152

152-
set(value: T): void {
153-
this._dirty = true;
153+
set(value: T, trackChanges: boolean = true): void {
154+
this._dirty = trackChanges;
154155
this._value = value;
155156
}
156157

src/transaction/predicate-impl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { get } from 'lodash';
12
import { IPredicate } from '../index';
23
import { FacetStorage } from './facet-storage';
34
import { IDiffEnvelope } from './transaction';
@@ -44,7 +45,9 @@ export class PredicateImpl<T = any, U = any> implements IPredicate<T, U> {
4445
}
4546

4647
this._data.push(node);
47-
this._diff.predicates.get(this)!.add(node);
48+
if (get(this._owner, 'trackChanges', true)) {
49+
this._diff.predicates.get(this)!.add(node);
50+
}
4851

4952
return this;
5053
}

src/transaction/transaction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Quad } from 'n3';
22
import uniqid from 'uniqid';
3+
import { set } from 'lodash';
34

45
import { DiffTracker } from './diff-tracker';
56
import { FacetStorage } from './facet-storage';
@@ -92,13 +93,14 @@ export class Transaction<T extends Object, V> implements ITransaction<T> {
9293

9394
public nodeFor<N extends Object>(nodeCls: Constructor<N>): N;
9495
public nodeFor<N extends Object, V extends Object>(nodeCls: Constructor<N>, data: V & { uid?: string }): N;
95-
public nodeFor<N extends Object, V extends Object>(nodeCls: Constructor<N>, data?: V & { uid?: string }): N {
96+
public nodeFor<N extends Object, V extends Object>(nodeCls: Constructor<N>, data?: V & { uid?: string }, trackChanges: boolean = true): N {
9697
const uids = MetadataStorage.Instance.uids.get(nodeCls.name);
9798
if (!uids || uids.length === 0) {
9899
throw new Error('Node must have a property decorated with @Uid');
99100
}
100101

101102
const nodeInstance = new nodeCls();
103+
set(nodeInstance, 'trackChanges', trackChanges)
102104
this.trackProperties(nodeInstance);
103105
this.trackPredicatesForFreshNode(nodeInstance);
104106

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,11 @@
949949
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
950950
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
951951

952+
"@types/lodash@^4.14.165":
953+
version "4.14.165"
954+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.165.tgz#74d55d947452e2de0742bad65270433b63a8c30f"
955+
integrity sha512-tjSSOTHhI5mCHTy/OOXYIhi2Wt1qcbHmuXD1Ha7q70CgI/I71afO4XtLb/cVexki1oVYchpul/TOuu3Arcdxrg==
956+
952957
"@types/long@*":
953958
version "4.0.0"
954959
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"

0 commit comments

Comments
 (0)