Module organization change due to Nim limitations.

Parent modules are exposed to submodules using their base class instead of
concepts, since using concepts is not possible to create a second level nested
modules.
This commit is contained in:
Sale Djenic 2021-10-14 12:23:39 +02:00 committed by Iuri Matias
parent 9f4eeffdea
commit 05705f219d
27 changed files with 156 additions and 133 deletions

View File

@ -1,18 +1,12 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
# Defines how parent module accesses this module
include ./private_interfaces/module_base_interface
include ./private_interfaces/module_access_interface
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this module view communicates with this module
include ./private_interfaces/module_view_delegate_interface
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this controller communicates with this module
include ./private_interfaces/module_controller_delegate_interface
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
c.chatSectionDidLoad()
# Defines how submodules of this module communicate with this module
# will be added if needed

View File

@ -1,25 +1,30 @@
import io_interface, view
import io_interface
import ../io_interface as delegate_interface
import view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
proc newModule*(delegate: delegate_interface.AccessInterface): Module =
result = Module()
result.delegate = delegate
result.view = newView()
result.view = newView(result)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
self.delegate.chatSectionDidLoad()
method load*(self: Module) =
self.view.load()
method isLoaded*[T](self: Module[T]): bool =
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.chatSectionDidLoad()

View File

@ -0,0 +1,8 @@
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,5 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
# Since nim doesn't support using concepts in second level nested types we
# define delegate interfaces within access interface.

View File

@ -0,0 +1,2 @@
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,19 +1,22 @@
import NimQml
import model
import io_interface
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
model: Model
proc setup(self: View) =
self.QObject.setup
self.model = newModel()
proc delete*(self: View) =
self.model.delete
self.QObject.delete
proc newView*(): View =
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.setup()
result.QObject.setup
result.delegate = delegate
result.model = newModel()
proc load*(self: View) =
self.delegate.viewDidLoad()

View File

@ -1,31 +1,31 @@
import Tables
import controller_interface
import io_interface
import ../../../../app_service/service/community/service as community_service
export controller_interface
type
Controller*[T: controller_interface.DelegateInterface] =
ref object of controller_interface.AccessInterface
delegate: T
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
id: string
communityService: community_service.ServiceInterface
proc newController*[T](delegate: T,
proc newController*(delegate: io_interface.AccessInterface,
id: string,
communityService: community_service.ServiceInterface):
Controller[T] =
result = Controller[T]()
Controller =
result = Controller()
result.delegate = delegate
result.id = id
result.communityService = communityService
method delete*[T](self: Controller[T]) =
method delete*(self: Controller) =
discard
method init*[T](self: Controller[T]) =
method init*(self: Controller) =
discard
method getId*(self: Controller): string =

View File

@ -15,10 +15,4 @@ method getId*(self: AccessInterface): string {.base.} =
method getCommunities*(self: AccessInterface): seq[community_service.Dto] {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c

View File

@ -1,24 +1,12 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
# Defines how parent module accesses this module
include ./private_interfaces/module_base_interface
include ./private_interfaces/module_access_interface
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this module view communicates with this module
include ./private_interfaces/module_view_delegate_interface
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this controller communicates with this module
include ./private_interfaces/module_controller_delegate_interface
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
c.communitySectionDidLoad()
# Defines how submodules of this module communicate with this module
# will be added if needed

View File

@ -1,39 +1,41 @@
import NimQml
import io_interface, view, controller
import io_interface
import ../io_interface as delegate_interface
import view, controller
import ../../../../app_service/service/community/service as community_service
export io_interface
type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*[T](delegate: T, id: string,
proc newModule*(delegate: delegate_interface.AccessInterface, id: string,
communityService: community_service.Service):
Module[T] =
result = Module[T]()
Module =
result = Module()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, id, communityService)
result.controller = controller.newController(result, id, communityService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
self.delegate.communitySectionDidLoad()
method load*(self: Module) =
self.view.load()
method isLoaded*[T](self: Module[T]): bool =
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
discard
self.moduleLoaded = true
self.delegate.communitySectionDidLoad()

View File

@ -0,0 +1,8 @@
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,5 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
# Since nim doesn't support using concepts in second level nested types we
# define delegate interfaces within access interface.

View File

@ -0,0 +1,2 @@
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,29 +1,29 @@
import Tables
import controller_interface
import io_interface
import ../../../app_service/service/community/service as community_service
export controller_interface
type
Controller*[T: controller_interface.DelegateInterface] =
ref object of controller_interface.AccessInterface
delegate: T
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
communityService: community_service.ServiceInterface
proc newController*[T](delegate: T,
proc newController*(delegate: io_interface.AccessInterface,
communityService: community_service.ServiceInterface):
Controller[T] =
result = Controller[T]()
Controller =
result = Controller()
result.delegate = delegate
result.communityService = communityService
method delete*[T](self: Controller[T]) =
method delete*(self: Controller) =
discard
method init*[T](self: Controller[T]) =
method init*(self: Controller) =
discard
method getCommunities*[T](self: Controller[T]): seq[community_service.Dto] =
method getCommunities*(self: Controller): seq[community_service.Dto] =
return self.communityService.getCommunities()

View File

@ -11,11 +11,4 @@ method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunities*(self: AccessInterface): seq[community_service.Dto] {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
raise newException(ValueError, "No implementation available")

View File

@ -1,22 +1,18 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
# Defines how parent module accesses this module
include ./private_interfaces/module_base_interface
include ./private_interfaces/module_access_interface
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this module view communicates with this module
include ./private_interfaces/module_view_delegate_interface
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Defines how this controller communicates with this module
include ./private_interfaces/module_controller_delegate_interface
# Defines how submodules of this module communicate with this module
include ./private_interfaces/module_chat_section_delegate_interface
include ./private_interfaces/module_community_section_delegate_interface
# This way (using concepts) is used only for the modules managed by AppController
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
c.mainDidLoad()
c.mainDidLoad()

View File

@ -19,20 +19,6 @@ type
chatSectionModule: chat_section_module.AccessInterface
communitySectionsModule: OrderedTable[string, community_section_module.AccessInterface]
#################################################
# Forward declaration section
# Controller Delegate Interface
# Chat Section Module Delegate Interface
proc chatSectionDidLoad*[T](self: Module[T])
# Community Section Module Delegate Interface
proc communitySectionDidLoad*[T](self: Module[T])
#################################################
proc newModule*[T](delegate: T,
communityService: community_service.Service):
Module[T] =
@ -40,16 +26,16 @@ proc newModule*[T](delegate: T,
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, communityService)
result.controller = controller.newController(result, communityService)
singletonInstance.engine.setRootContextProperty("mainModule", result.viewVariant)
# Submodules
result.chatSectionModule = chat_section_module.newModule[Module[T]](result)
result.chatSectionModule = chat_section_module.newModule(result)
result.communitySectionsModule = initOrderedTable[string, community_section_module.AccessInterface]()
let communities = result.controller.getCommunities()
for c in communities:
result.communitySectionsModule[c.id] = community_section_module.newModule[Module[T]](result,
result.communitySectionsModule[c.id] = community_section_module.newModule(result,
c.id, communityService)
method delete*[T](self: Module[T]) =
@ -87,11 +73,11 @@ proc checkIfModuleDidLoad [T](self: Module[T]) =
self.delegate.mainDidLoad()
proc chatSectionDidLoad*[T](self: Module[T]) =
method chatSectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
proc communitySectionDidLoad*[T](self: Module[T]) =
method communitySectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method viewDidLoad*[T](self: Module[T]) =
discard
self.checkIfModuleDidLoad()

View File

@ -0,0 +1,5 @@
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,5 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
# Since nim doesn't support using concepts in second level nested types we
# define delegate interfaces within access interface.

View File

@ -0,0 +1,2 @@
method chatSectionDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,2 @@
method communitySectionDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,2 @@
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,8 @@
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,8 @@
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")