Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit 7f525fa

Browse files
author
Dr. Safi
committed
Fixed - rethinkdb connection being inconsistant directly on controller
1 parent 4ab1248 commit 7f525fa

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

module/reusableNestedUnit/Controller.class.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction
88
import { extendedSubclassPattern } from 'appscript/utilityFunction/extendedSubclassPattern.js'
99
import { superclassInstanceContextPattern, cacheInstance } from 'appscript/utilityFunction/superclassInstanceContextPattern.js'
1010
import { mix } from 'mixwith'
11+
import assert from 'assert'
1112

1213
/**
1314
* @class
@@ -18,13 +19,14 @@ export default ({
1819
Superclass = EventEmitter, // defaulting to EventEmitter and not Object / Function because extending Object/Function manipulates this prototype in new calls for some reason.
1920
mixin,
2021
rethinkdbConnection = Superclass.rethinkdbConnection
21-
}) => {
22+
} = {}) => {
23+
Superclass.rethinkdbConnection = rethinkdbConnection // Setting this variable on Controller class below causes issues, which maybe related to the way rethinkdb is called or the proxies encapsulating the class.
2224
let mixinArray = [/*commonMethod*/]
2325
let self =
2426
@add({ to: 'static'}, {
2527
createInstance,
2628
populateInstancePropertyFromJson,
27-
addStaticSubclassToClassArray
29+
addStaticSubclassToClassArray,
2830
})
2931
@add({ to: 'prototype'}, {
3032
populateInstancePropertyFromJson_this
@@ -35,15 +37,16 @@ export default ({
3537
@conditional({ condition: mixin, decorator: applyMixin({ mixin }) })
3638
@superclassInstanceContextPattern() // applied on the mixin i.e. specific controller.
3739
class ReusableController extends mix(Superclass).with(...mixinArray) {
38-
39-
static rethinkdbConnection = rethinkdbConnection
4040

4141
@cacheInstance({
4242
cacheArrayName: 'nestedUnit',
4343
keyArgumentName: 'nestedUnitKey'
4444
})
4545
async getNestedUnit({ nestedUnitKey, additionalChildNestedUnit = [], pathPointerKey = null}) {
4646
let instance = await this.callSubclass('NestedUnit', [nestedUnitKey])
47+
if(Object.getPrototypeOf(self.rethinkdbConnection).constructor.name == 'Object') {
48+
console.log('Opsie !!')
49+
}
4750
await instance.reflectDatabaseDataToAppObject()
4851
// add children trees:
4952
instance.additionalChildNestedUnit = additionalChildNestedUnit
@@ -73,6 +76,7 @@ export default ({
7376
queryFunc = this.constructor.getDocumentQuery,
7477
connection = self.rethinkdbConnection
7578
} = {}) {
79+
assert.strictEqual(Object.getPrototypeOf(self.rethinkdbConnection).constructor.name, 'TcpConnection')
7680
if(!('jsonData' in object)) { // if not already populated with data.
7781
let jsonData = await queryFunc({ key, connection })
7882
await this.populateInstancePropertyFromJson_this({ jsonData })

module/reusableNestedUnit/Unit.class.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { classDecorator as prototypeChainDebug} from 'appscript/module/prototypeChainDebug'
22
import { add, execute, applyMixin, conditional, executeOnceForEachInstance } from 'appscript/utilityFunction/decoratorUtility.js'
3+
import assert from 'assert'
34

45
export default ({ Superclass }) => {
56
let self =
@@ -24,6 +25,7 @@ export default ({ Superclass }) => {
2425
getDocument, // function
2526
extract = null // object with two properties - extract: { sourceKey: 'key from source object', destinationKey: 'key to "this" destination' }
2627
}) {
28+
assert.strictEqual(Object.getPrototypeOf(self.rethinkdbConnection).constructor.name, 'TcpConnection')
2729
let File = await getDocument({
2830
key: fileKey,
2931
connection: self.rethinkdbConnection

module/reusableNestedUnit/entrypoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function createStaticInstanceClasses({
8484
counter[cacheName] ++
8585
}
8686
}
87-
87+
8888
// Call class producer functions to return a new class with the specific connections.
8989
let Controller = ControllerFunc({
9090
methodInstanceName: cacheName,

0 commit comments

Comments
 (0)