Skip to content

Commit 5d13a59

Browse files
committed
update
1 parent 626be8c commit 5d13a59

File tree

2 files changed

+79
-49
lines changed

2 files changed

+79
-49
lines changed

README.md

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,64 @@ PureMVC is a lightweight framework for creating applications based upon the clas
1111
```commandline
1212
pip install PureMVC
1313
```
14-
<!---
15-
Documentation: Update version docs/source/conf.py
16-
Update: python3 -m pip install --upgrade pip
17-
Development: pip install -e .
18-
Type Testing:
19-
pip install mypy
20-
mypy ./src
21-
Testing: pytest test/
22-
Build: python -m build
23-
Publish: twine upload dist/*
24-
25-
Documentation:
26-
Install: pip install sphinx sphinx_rtd_theme
27-
Generate:
28-
mkdir docs && cd docs && sphinx-quickstart --sep -p PureMVC -a "Saad Shams" -v "2.0.0" -r "BSD 3-Clause License" -l "en"
29-
cd ../ && sphinx-apidoc -o docs/source src/puremvc && cd docs && make html && cd .. && open docs/build/html/index.html
30-
31-
Update
32-
sphinx-apidoc -o docs/source src/puremvc --force && cd docs && make html && cd .. && open docs/build/html/index.html
33-
34-
conf.py
35-
import os
36-
import sys
37-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'src')))
38-
extensions = ['sphinx.ext.autodoc']
39-
html_theme = 'sphinx_rtd_theme'
40-
41-
index.rst
42-
13: modules
43-
-->
14+
---
15+
16+
## Development
17+
18+
### Install Dependency (Editable Package)
19+
```shell
20+
pip install -e .
21+
```
22+
23+
### Type Checking
24+
```shell
25+
pip install mypy
26+
mypy ./src
27+
```
28+
29+
### Testing
30+
```shell
31+
pytest test/
32+
```
33+
34+
### Build & Publish
35+
```shell
36+
python -m build
37+
twine upload dist/*
38+
```
39+
40+
### Generate Documentation with Sphinx
41+
- Install Sphinx and theme:
42+
```shell
43+
pip install sphinx sphinx_rtd_theme
44+
```
45+
- Initialize Docs
46+
```shell
47+
mkdir docs && cd docs
48+
sphinx-quickstart --sep -p PureMVC -a "Saad Shams" -v "2.0" -r "2.0.0" -l "en"
49+
```
50+
- Generate API docs and build HTML:
51+
```shell
52+
cd ../ && sphinx-apidoc -o docs/source src/puremvc && cd docs && make html && cd .. && open docs/build/html/index.html
53+
```
54+
55+
- To update docs after code changes:
56+
```shell
57+
sphinx-apidoc -o docs/source src/puremvc --force && cd docs && make html && cd .. && open docs/build/html/index.html
58+
```
59+
- Snippet: conf.py
60+
```python
61+
import os
62+
import sys
63+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'src')))
64+
extensions = ['sphinx.ext.autodoc']
65+
html_theme = 'sphinx_rtd_theme'
66+
```
67+
- Snippet: index.rst
68+
```
69+
13: modules
70+
```
71+
---
4472

4573
## Status
4674
Production - [Version 2.0.2](https://github.com/PureMVC/puremvc-python-multicore-framework/blob/master/VERSION)

src/puremvc/core/View.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ def notify_observers(self, notification: INotification) -> None:
120120
:type notification: INotification
121121
:return: None
122122
"""
123-
# Get a reference to the observers list for this notification name
123+
# Get a reference to the observer list for this notification name
124124
with self.observerMapLock:
125125
observers = self.observerMap.get(notification.name)
126126

127-
if observers:
128-
# Copy observers (observers[:]) from reference array to working array,
129-
# since the reference array may change during the notification loo
130-
for observer in observers[:]:
131-
# Notify Observers from the working array
132-
observer.notify_observer(notification)
127+
# Copy observers (observers[:]) from reference array to a working array,
128+
# since the reference array may change during the notification loo
129+
# Safe iteration, create a shallow copy of observers or use an empty list if observers is None or falsy.
130+
for observer in list(observers or []):
131+
# Notify Observers from the working array
132+
observer.notify_observer(notification)
133133

134134
def remove_observer(self, notification_name: str, notify_context: Any) -> None:
135135
"""
@@ -172,18 +172,19 @@ def register_mediator(self, mediator: IMediator) -> None:
172172
:return: None
173173
"""
174174
# Do not allow re-registration (you must to removeMediator first)
175-
with self.mediatorMapLock:
176-
if self.mediatorMap.get(mediator.mediator_name):
177-
return
175+
if self.has_mediator(mediator.mediator_name):
176+
return
177+
178+
mediator.initialize_notifier(self.multitonKey)
178179

179-
mediator.initialize_notifier(self.multitonKey)
180+
with self.mediatorMapLock:
180181
self.mediatorMap[mediator.mediator_name] = mediator
181182

183+
observer = Observer(mediator.handle_notification, mediator)
184+
182185
interests = mediator.list_notification_interests()
183-
if interests:
184-
observer = Observer(mediator.handle_notification, mediator)
185-
for interest in interests:
186-
self.register_observer(interest, observer)
186+
for interest in interests:
187+
self.register_observer(interest, observer)
187188

188189
mediator.on_register()
189190

@@ -222,11 +223,12 @@ def remove_mediator(self, mediator_name: str) -> Optional[IMediator]:
222223
"""
223224
with self.mediatorMapLock:
224225
mediator = self.mediatorMap.get(mediator_name)
225-
if not mediator: return None
226-
for interest in mediator.list_notification_interests():
227-
self.remove_observer(interest, mediator)
228226

229-
del self.mediatorMap[mediator_name]
227+
if not mediator: return None
228+
for interest in mediator.list_notification_interests():
229+
self.remove_observer(interest, mediator)
230+
231+
del self.mediatorMap[mediator_name]
230232

231233
mediator.on_remove()
232234
return mediator

0 commit comments

Comments
 (0)