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

Commit 063cda7

Browse files
author
Dr. Safi
committed
Moved common subclasses methods to superclass.
1 parent 13212c5 commit 063cda7

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

module/reusableNestedUnit/Controller.class.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ export default ({
7878
await instance.initializeInstance()
7979
return instance
8080
}
81+
82+
/**
83+
* @description gets document from database using documentKey and populates the data to the instance.
84+
* during which 'jsonData' property is set. if it is set, it means that the instance is already populated with data.
85+
*
86+
*/
87+
async initializeInstance() {
88+
let Class = this.constructor
89+
if(!('jsonData' in this)) { // if not already populated with data.
90+
let jsonData = await Class.getDocumentQuery(Class.rethinkdbConnection, this.key)
91+
await this.populateInstancePropertyFromJson_this(jsonData)
92+
}
93+
}
8194

8295
}
8396

module/reusableNestedUnit/NestedUnit.class.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ export default ({ Superclass }) => {
2323
*
2424
*/
2525
async initializeInstance() {
26-
let Class = this.constructor
27-
if(!('jsonData' in this)) { // if not already populated with data.
28-
let jsonData = await Class.getDocumentQuery(Class.rethinkdbConnection, this.key)
29-
await this.populateInstancePropertyFromJson_this(jsonData)
30-
// reorder insertion points
31-
if(this.insertionPoint) {
32-
await this.insertionPoint.sort((prior, subsequent) => {
33-
return (prior.order <= subsequent.order) ? -1 : 1;
34-
})
35-
}
26+
await super.initializeInstance()
27+
// reorder insertion points
28+
if(!('jsonData' in this) && this.insertionPoint) {
29+
await this.insertionPoint.sort((prior, subsequent) => {
30+
return (prior.order <= subsequent.order) ? -1 : 1;
31+
})
3632
}
3733
}
3834

module/reusableNestedUnit/Unit.class.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ export default ({ Superclass }) => {
1717
this.key = databaseDocumentKey
1818
return this
1919
}
20-
21-
/**
22-
* @description gets document from database using documentKey and populates the data to the instance.
23-
*
24-
*/
25-
async initializeInstance() {
26-
let Class = this.constructor
27-
if(!('jsonData' in this)) { // if not already populated with data.
28-
let jsonData = await Class.getDocumentQuery(Class.rethinkdbConnection, this.key)
29-
await this.populateInstancePropertyFromJson_this(jsonData)
30-
}
31-
}
3220
}
3321

3422
return self

module/reusableNestedUnit/implementation/template/NestedUnit.class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import filesystem from 'fs'
55
import { classDecorator as prototypeChainDebug} from 'appscript/module/prototypeChainDebug'
66
import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction/decoratorUtility.js'
77
import { extendedSubclassPattern } from 'appscript/utilityFunction/extendedSubclassPattern.js'
8+
import promiseProperRace from 'appscript/utilityFunction/promiseProperRace.js'
89

910
let getTableDocument = {
1011
generate: require('appscript/utilityFunction/database/query/getTableDocument.query.js'),
1112
instance: []
1213
}
1314
getTableDocument.instance['template_viewNestedUnit'] = getTableDocument.generate('template_viewNestedUnit')
14-
import promiseProperRace from 'appscript/utilityFunction/promiseProperRace.js'
1515

1616
export default ({ Superclass }) => {
1717
let self =

0 commit comments

Comments
 (0)