Skip to content

Commit 577b8f6

Browse files
committed
Keep context in subscribe methods.
1 parent fd853a7 commit 577b8f6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/result.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Result {
9494
let onCompletedOriginal = observer.onCompleted;
9595
let onCompletedWrapper = (metadata) => {
9696
this.summary = new ResultSummary(this._statement, this._parameters, metadata);
97-
onCompletedOriginal(metadata);
97+
onCompletedOriginal.call(observer, metadata);
9898
}
9999
observer.onCompleted = onCompletedWrapper;
100100
this._streamObserver.subscribe(observer);

test/session.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ describe('session', function() {
2222
});
2323
});
2424

25+
it('should keep context in subscribe methods ', function(done) {
26+
// Given
27+
var driver = neo4j.driver("neo4j://localhost");
28+
function myObserver(){
29+
this.local = 'hello';
30+
var privateLocal = 'hello';
31+
this.onNext = function() {
32+
expect(privateLocal).toBe('hello');
33+
expect(this.local).toBe('hello');
34+
};
35+
this.onCompleted = function() {
36+
expect(privateLocal).toBe('hello');
37+
expect(this.local).toBe('hello');
38+
driver.close();
39+
done();
40+
}
41+
}
42+
43+
// When & Then
44+
driver.session().run( "RETURN 1.0 AS a").subscribe(new myObserver());
45+
});
46+
2547
it('should call observers onError on error ', function(done) {
2648
// Given
2749
var driver = neo4j.driver("neo4j://localhost");

0 commit comments

Comments
 (0)