Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
saadshams committed Dec 13, 2023
1 parent a1449ea commit 8734d7a
Show file tree
Hide file tree
Showing 49 changed files with 688 additions and 681 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.idea/
.DS_Store
6 changes: 4 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PureMVC Standard Framework for Go
--------------------------------------------------------------------------
Release Date: 04/25/19
Release Date: 12/12/23
Platform: Go
Version: 1
Revision: 0
Revision: 1
Minor: 0
Author: Saad Shams <[email protected]>
--------------------------------------------------------------------------
1.0 - Initial release.

1.1 - Updated to use Go 1.21. Minor Updates.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/puremvc/puremvc-go-standard-framework

go 1.12
go 1.21
76 changes: 38 additions & 38 deletions src/core/controller/Controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

/*
A Singleton IController implementation.
Controller A Singleton IController implementation.
In PureMVC, the Controller class follows the
'Command and Controller' strategy, and assumes these
Expand Down Expand Up @@ -47,93 +47,93 @@ var instance interfaces.IController // The Singleton Controller instanceMap.
var instanceMutex sync.RWMutex // instanceMap Mutex

/*
Controller Singleton Factory method.
GetInstance Controller Singleton Factory method.
- parameter controllerFunc: reference that returns IController
- parameter factory: reference that returns IController
- returns: the Singleton instance
- returns: the Singleton instance
*/
func GetInstance(controllerFunc func() interfaces.IController) interfaces.IController {
func GetInstance(factory func() interfaces.IController) interfaces.IController {
instanceMutex.Lock()
defer instanceMutex.Unlock()

if instance == nil {
instance = controllerFunc()
instance = factory()
instance.InitializeController()
}
return instance
}

/*
Initialize the Singleton Controller instance.
InitializeController Initialize the Singleton Controller instance.
Called automatically by the GetInstance.
Called automatically by the GetInstance.
Note that if you are using a subclass of View
in your application, you should also subclass Controller
and override the InitializeController method in the
following way:
Note that if you are using a subclass of View
in your application, you should also subclass Controller
and override the InitializeController method in the
following way:
func (self *MyController) InitializeController() {
self.commandMap = map[string]func() interfaces.ICommand{}
self.view = MyView.GetInstance(func() interfaces.IView { return &MyView{} })
}
func (self *MyController) InitializeController() {
self.commandMap = map[string]func() interfaces.ICommand{}
self.view = MyView.GetInstance(func() interfaces.IView { return &MyView{} })
}
*/
func (self *Controller) InitializeController() {
self.commandMap = map[string]func() interfaces.ICommand{}
self.view = view.GetInstance(func() interfaces.IView { return &view.View{} })
}

/*
If an ICommand has previously been registered
to handle a the given INotification, then it is executed.
ExecuteCommand If an ICommand has previously been registered
to handle the given INotification, then it is executed.
- parameter note: an INotification
- parameter note: an INotification
*/
func (self *Controller) ExecuteCommand(notification interfaces.INotification) {
self.commandMapMutex.RLock()
defer self.commandMapMutex.RUnlock()

var commandFunc = self.commandMap[notification.Name()]
if commandFunc == nil {
var factory = self.commandMap[notification.Name()]
if factory == nil {
return
}
commandInstance := commandFunc()
commandInstance := factory()
commandInstance.InitializeNotifier()
commandInstance.Execute(notification)
}

/*
Register a particular ICommand class as the handler
for a particular INotification.
RegisterCommand Register a particular ICommand class as the handler
for a particular INotification.
If an ICommand has already been registered to
handle INotifications with this name, it is no longer
used, the new ICommand is used instead.
If an ICommand has already been registered to
handle INotifications with this name, it is no longer
used, the new ICommand is used instead.
The Observer for the new ICommand is only created if this the
first time an ICommand has been regisered for this Notification name.
The Observer for the new ICommand is only created if this the
first time an ICommand has been regisered for this Notification name.
- parameter notificationName: the name of the INotification
- parameter notificationName: the name of the INotification
- parameter commandFunc: reference that returns ICommand
- parameter factory: reference that returns ICommand
*/
func (self *Controller) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) {
func (self *Controller) RegisterCommand(notificationName string, factory func() interfaces.ICommand) {
self.commandMapMutex.Lock()
defer self.commandMapMutex.Unlock()

if self.commandMap[notificationName] == nil {
self.view.RegisterObserver(notificationName, &observer.Observer{Notify: self.ExecuteCommand, Context: self})
}
self.commandMap[notificationName] = commandFunc
self.commandMap[notificationName] = factory
}

/*
Check if a Command is registered for a given Notification
HasCommand Check if a Command is registered for a given Notification
- parameter notificationName:
- parameter notificationName:
- returns: whether a Command is currently registered for the given notificationName.
- returns: whether a Command is currently registered for the given notificationName.
*/
func (self *Controller) HasCommand(notificationName string) bool {
self.commandMapMutex.RLock()
Expand All @@ -143,9 +143,9 @@ func (self *Controller) HasCommand(notificationName string) bool {
}

/*
Remove a previously registered ICommand to INotification mapping.
RemoveCommand Remove a previously registered ICommand to INotification mapping.
- parameter notificationName: the name of the INotification to remove the ICommand mapping for
- parameter notificationName: the name of the INotification to remove the ICommand mapping for
*/
func (self *Controller) RemoveCommand(notificationName string) {
self.commandMapMutex.Lock()
Expand Down
46 changes: 23 additions & 23 deletions src/core/model/Model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

/*
A Singleton IModel implementation.
Model A Singleton IModel implementation.
In PureMVC, the Model class provides
access to model objects (Proxies) by named lookup.
Expand All @@ -40,39 +40,39 @@ var instance interfaces.IModel // The Singleton Model instance.
var instanceMutex sync.RWMutex // instanceMutex for thread safety

/*
Model Singleton Factory method.
GetInstance Model Singleton Factory method.
- parameter modelFunc: reference that returns IModel
- parameter factory: reference that returns IModel
- returns: the instance returned by the passed modelFunc
- returns: the instance returned by the passed modelFunc
*/
func GetInstance(modelFunc func() interfaces.IModel) interfaces.IModel {
func GetInstance(factory func() interfaces.IModel) interfaces.IModel {
instanceMutex.Lock()
defer instanceMutex.Unlock()

if instance == nil {
instance = modelFunc()
instance = factory()
instance.InitializeModel()
}
return instance
}

/*
Initialize the Model instance.
InitializeModel Initialize the Model instance.
Called automatically by the GetInstance, this
is your opportunity to initialize the Singleton
instance in your subclass without overriding the
constructor.
Called automatically by the GetInstance, this
is your opportunity to initialize the Singleton
instance in your subclass without overriding the
constructor.
*/
func (self *Model) InitializeModel() {
self.proxyMap = map[string]interfaces.IProxy{}
}

/*
Register an IProxy with the Model.
RegisterProxy Register an IProxy with the Model.
- parameter proxy: an IProxy to be held by the Model.
- parameter proxy: an IProxy to be held by the Model.
*/
func (self *Model) RegisterProxy(proxy interfaces.IProxy) {
self.proxyMapMutex.Lock()
Expand All @@ -84,25 +84,25 @@ func (self *Model) RegisterProxy(proxy interfaces.IProxy) {
}

/*
Retrieve an IProxy from the Model.
RetrieveProxy Retrieve an IProxy from the Model.
- parameter proxyName:
- parameter proxyName:
- returns: the IProxy instance previously registered with the given proxyName.
- returns: the IProxy instance previously registered with the given proxyName.
*/
func (self *Model) RetrieveProxy(proxyName string) interfaces.IProxy {
self.proxyMapMutex.RLock();
self.proxyMapMutex.RLock()
defer self.proxyMapMutex.RUnlock()

return self.proxyMap[proxyName]
}

/*
Remove an IProxy from the Model.
RemoveProxy Remove an IProxy from the Model.
- parameter proxyName: name of the IProxy instance to be removed.
- parameter proxyName: name of the IProxy instance to be removed.
- returns: the IProxy that was removed from the Model
- returns: the IProxy that was removed from the Model
*/
func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy {
self.proxyMapMutex.Lock()
Expand All @@ -117,11 +117,11 @@ func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy {
}

/*
Check if a Proxy is registered
HasProxy Check if a Proxy is registered
- parameter proxyName:
- parameter proxyName:
- returns: whether a Proxy is currently registered with the given proxyName.
- returns: whether a Proxy is currently registered with the given proxyName.
*/
func (self *Model) HasProxy(proxyName string) bool {
self.proxyMapMutex.RLock()
Expand Down
Loading

0 comments on commit 8734d7a

Please sign in to comment.