Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
saadshams committed Apr 27, 2019
1 parent 9470f71 commit 077dbdc
Show file tree
Hide file tree
Showing 50 changed files with 781 additions and 686 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require github.com/puremvc/puremvc-go-multicore-framework v1.0.0
* [Pipes](https://github.com/PureMVC/puremvc-go-util-pipes/wiki)

## Platforms / Technologies
* [Go](https://en.wikipedia.org/wiki/Go_(programming_language))
* [FreeBSD](https://en.wikipedia.org/wiki/FreeBSD)
* [Linux](https://en.wikipedia.org/wiki/Linux)
* [MacOS](https://en.wikipedia.org/wiki/MacOS)
Expand Down
93 changes: 50 additions & 43 deletions src/core/controller/Controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,45 @@ import (
"sync"
)

/**
A Multiton `IController` implementation.
/*
A Multiton IController implementation.
In PureMVC, the `Controller` class follows the
In PureMVC, the Controller class follows the
'Command and Controller' strategy, and assumes these
responsibilities:
* Remembering which `ICommand`s are intended to handle which `INotifications`.
* Registering itself as an `IObserver` with the `View` for each `INotification` that it has an `ICommand` mapping for.
* Creating a new instance of the proper `ICommand` to handle a given `INotification` when notified by the `View`.
* Calling the `ICommand`'s `execute` method, passing in the `INotification`.
* Remembering which ICommands are intended to handle which INotifications.
Your application must register `ICommands` with the
* Registering itself as an IObserver with the View for each INotification that it has an ICommand mapping for.
* Creating a new instance of the proper ICommand to handle a given INotification when notified by the View.
* Calling the ICommand's execute method, passing in the INotification.
Your application must register ICommands with the
Controller.
The simplest way is to subclass `Facade`,
and use its `initializeController` method to add your
The simplest way is to subclass Facade,
and use its initializeController method to add your
registrations.
*/
type Controller struct {
Key string // The Multiton Key for this Core
commandMap map[string]func() interfaces.ICommand // Mapping of Notification names to funcs that returns `ICommand` Class instances
commandMap map[string]func() interfaces.ICommand // Mapping of Notification names to funcs that returns ICommand Class instances
commandMapMutex sync.RWMutex // Mutex for commandMap
view interfaces.IView // Local reference to View
}

var instanceMap = map[string]interfaces.IController{} // The Multiton Controller instanceMap.
var instanceMapMutex sync.RWMutex // instanceMap Mutex

/**
`Controller` Multiton Factory method.
/*
Controller Multiton Factory method.
- parameter key: multitonKey
- parameter controllerFunc: reference that returns `IController`
- parameter controllerFunc: reference that returns IController
- returns: the Multiton instance
*/
func GetInstance(key string, controllerFunc func() interfaces.IController) interfaces.IController {
Expand All @@ -62,31 +67,31 @@ func GetInstance(key string, controllerFunc func() interfaces.IController) inter
return instanceMap[key]
}

/**
Initialize the Multiton `Controller` instance.
/*
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.
/*
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()
Expand All @@ -101,19 +106,20 @@ func (self *Controller) ExecuteCommand(notification interfaces.INotification) {
commandInstance.Execute(notification)
}

/**
Register a particular `ICommand` class as the handler
for a particular `INotification`.
/*
Register a particular ICommand class as the handler
for a particular INotification.
If an `ICommand` has already been registered to
handle `INotification`s 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.
- parameter notificationName: the name of the `INotification`
- parameter commandFunc: reference that returns `ICommand`
- parameter notificationName: the name of the INotification
- parameter commandFunc: reference that returns ICommand
*/
func (self *Controller) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) {
self.commandMapMutex.Lock()
Expand All @@ -125,11 +131,12 @@ func (self *Controller) RegisterCommand(notificationName string, commandFunc fun
self.commandMap[notificationName] = commandFunc
}

/**
/*
Check if a Command is registered for a given Notification
- 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 @@ -138,10 +145,10 @@ func (self *Controller) HasCommand(notificationName string) bool {
return self.commandMap[notificationName] != nil
}

/**
Remove a previously registered `ICommand` to `INotification` mapping.
/*
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 @@ -153,7 +160,7 @@ func (self *Controller) RemoveCommand(notificationName string) {
}
}

/**
/*
Remove an IController instance
- parameter multitonKey: of IController instance to remove
Expand Down
80 changes: 43 additions & 37 deletions src/core/model/Model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ import (
"sync"
)

/**
A Multiton `IModel` implementation.
/*
A Multiton IModel implementation.
In PureMVC, the `Model` class provides
In PureMVC, the Model class provides
access to model objects (Proxies) by named lookup.
The `Model` assumes these responsibilities:
The Model assumes these responsibilities:
* Maintain a cache of `IProxy` instances.
* Provide methods for registering, retrieving, and removing `IProxy` instances.
* Maintain a cache of IProxy instances.
Your application must register `IProxy` instances
with the `Model`. Typically, you use an
`ICommand` to create and register `IProxy`
instances once the `Facade` has initialized the Core
* Provide methods for registering, retrieving, and removing IProxy instances.
Your application must register IProxy instances
with the Model. Typically, you use an
ICommand to create and register IProxy
instances once the Facade has initialized the Core
actors.
*/
type Model struct {
Expand All @@ -39,23 +40,13 @@ type Model struct {
var instanceMap = map[string]interfaces.IModel{} // The Multiton Model instanceMap.
var instanceMapMutex sync.RWMutex // instanceMapMutex for thread safety

/**
Initialize the `Model` instance.
/*
Model Multiton Factory method.
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{}
}
- parameter key: multitonKey
/**
`Model` Multiton Factory method.
- parameter modelFunc: reference that returns IModel
- parameter key: multitonKey
- parameter modelFunc: reference that returns `IModel`
- returns: the instance returned by the passed modelFunc
*/
func GetInstance(key string, modelFunc func() interfaces.IModel) interfaces.IModel {
Expand All @@ -69,10 +60,22 @@ func GetInstance(key string, modelFunc func() interfaces.IModel) interfaces.IMod
return instanceMap[key]
}

/**
Register an `IProxy` with the `Model`.
/*
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.
*/
func (self *Model) InitializeModel() {
self.proxyMap = map[string]interfaces.IProxy{}
}

/*
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 @@ -83,11 +86,12 @@ func (self *Model) RegisterProxy(proxy interfaces.IProxy) {
proxy.OnRegister()
}

/**
Retrieve an `IProxy` from the `Model`.
/*
Retrieve an IProxy from the Model.
- 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();
Expand All @@ -96,11 +100,12 @@ func (self *Model) RetrieveProxy(proxyName string) interfaces.IProxy {
return self.proxyMap[proxyName]
}

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

/**
/*
Check if a Proxy is registered
- 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 @@ -127,7 +133,7 @@ func (self *Model) HasProxy(proxyName string) bool {
return self.proxyMap[proxyName] != nil
}

/**
/*
Remove an IModel instance
- parameter multitonKey: of IModel instance to remove
Expand Down
Loading

0 comments on commit 077dbdc

Please sign in to comment.