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 b442c78 commit 6c8e774
Show file tree
Hide file tree
Showing 51 changed files with 680 additions and 672 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PureMVC is a lightweight framework for creating applications based upon the clas

## Installation
```
require github.com/puremvc/puremvc-go-multicore-framework v1.0.0
require github.com/puremvc/puremvc-go-multicore-framework v1.1.0
```

## Utilities
Expand All @@ -21,7 +21,7 @@ require github.com/puremvc/puremvc-go-multicore-framework v1.0.0
* [Windows](https://en.wikipedia.org/wiki/Microsoft_Windows)

## Status
Production - [Version 1.0](https://github.com/PureMVC/puremvc-go-multicore-framework/blob/master/VERSION)
Production - [Version 1.1](https://github.com/PureMVC/puremvc-go-multicore-framework/blob/master/VERSION)

## License
* PureMVC MultiCore Framework for Go - Copyright © 2019 [Saad Shams](https://www.linkedin.com/in/muizz/)
Expand Down
6 changes: 4 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PureMVC MultiCore 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-multicore-framework

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

/*
A Multiton IController implementation.
Controller A Multiton IController implementation.
In PureMVC, the Controller class follows the
'Command and Controller' strategy, and assumes these
Expand Down Expand Up @@ -48,95 +48,95 @@ var instanceMap = map[string]interfaces.IController{} // The Multiton Controller
var instanceMapMutex sync.RWMutex // instanceMap Mutex

/*
Controller Multiton Factory method.
GetInstance Controller Multiton Factory method.
- parameter key: multitonKey
- parameter key: multitonKey
- parameter controllerFunc: reference that returns IController
- parameter factory reference that returns IController
- returns: the Multiton instance
- returns: the Multiton instance
*/
func GetInstance(key string, controllerFunc func() interfaces.IController) interfaces.IController {
func GetInstance(key string, factory func() interfaces.IController) interfaces.IController {
instanceMapMutex.Lock()
defer instanceMapMutex.Unlock()

if instanceMap[key] == nil {
instanceMap[key] = controllerFunc()
instanceMap[key] = factory()
instanceMap[key].InitializeController()
}
return instanceMap[key]
}

/*
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(self.Key, func() interfaces.IView { return &MyView{Key: self.Key} })
}
func (self *MyController) InitializeController() {
self.commandMap = map[string]func() interfaces.ICommand{}
self.view = MyView.GetInstance(self.Key, func() interfaces.IView { return &MyView{Key: self.Key} })
}
*/
func (self *Controller) InitializeController() {
self.commandMap = map[string]func() interfaces.ICommand{}
self.view = view.GetInstance(self.Key, func() interfaces.IView { return &view.View{Key: self.Key} })
}

/*
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 a 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(self.Key)
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 @@ -146,9 +146,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 All @@ -161,9 +161,9 @@ func (self *Controller) RemoveCommand(notificationName string) {
}

/*
Remove an IController instance
RemoveController Remove an IController instance
- parameter multitonKey: of IController instance to remove
- parameter multitonKey: of IController instance to remove
*/
func RemoveController(key string) {
instanceMapMutex.Lock()
Expand Down
52 changes: 26 additions & 26 deletions src/core/model/Model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

/*
A Multiton IModel implementation.
Model A Multiton IModel implementation.
In PureMVC, the Model class provides
access to model objects (Proxies) by named lookup.
Expand All @@ -41,41 +41,41 @@ var instanceMap = map[string]interfaces.IModel{} // The Multiton Model instanceM
var instanceMapMutex sync.RWMutex // instanceMapMutex for thread safety

/*
Model Multiton Factory method.
GetInstance Model Multiton Factory method.
- parameter key: multitonKey
- parameter key: multitonKey
- 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 factory
*/
func GetInstance(key string, modelFunc func() interfaces.IModel) interfaces.IModel {
func GetInstance(key string, factory func() interfaces.IModel) interfaces.IModel {
instanceMapMutex.Lock()
defer instanceMapMutex.Unlock()

if instanceMap[key] == nil {
instanceMap[key] = modelFunc()
instanceMap[key] = factory()
instanceMap[key].InitializeModel()
}
return instanceMap[key]
}

/*
Initialize the Model instance.
InitializeModel Initialize the Model instance.
Called automatically by the GetInstance, this
is your opportunity to initialize the Multiton
instance in your subclass without overriding the
constructor.
Called automatically by the GetInstance, this
is your opportunity to initialize the Multiton
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 @@ -87,25 +87,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 @@ -120,11 +120,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 All @@ -134,9 +134,9 @@ func (self *Model) HasProxy(proxyName string) bool {
}

/*
Remove an IModel instance
RemoveModel Remove an IModel instance
- parameter multitonKey: of IModel instance to remove
- parameter multitonKey: of IModel instance to remove
*/
func RemoveModel(key string) {
instanceMapMutex.Lock()
Expand Down
Loading

0 comments on commit 6c8e774

Please sign in to comment.