You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/phet-software-design-patterns.md
+2-6
Original file line number
Diff line number
Diff line change
@@ -702,7 +702,7 @@ PhET widely uses the observer pattern described in https://en.wikipedia.org/wiki
702
702
##### Role in MVC
703
703
Please see the [Model-View-Controller (MVC)](https://github.com/phetsims/phet-info/blob/master/doc/phet-software-design-patterns.md#model-view-controller-mvc) section of this document for context.
704
704
705
-
In short, the observer pattern acts as a key communicator within the model-view hierarchy of PhET simulations. The model is oblivious to the view, so the model uses the observer pattern for the view (which has a reference to the model) to observe the state of the model and correctly render a mirrored view representation.
705
+
In short, the observer pattern acts as a key communicator within the model-view hierarchy of PhET simulations. The model is oblivious to the view, so the view uses the observer pattern for the model to observe the state of the model and correctly render a mirrored view representation.
706
706
707
707
See for example:
708
708
```js
@@ -787,8 +787,6 @@ PhET widely uses the observer pattern described in https://en.wikipedia.org/wiki
Multilink is a convenience classthat is used to observe multiple Properties with the same observer functionality. Similar to DerivedProperty, it has its "dependencies"of Properties, and when any dependency's value changes, the observer is invoked with the values of the dependencies in corresponding order. However, it is *not* a subclass of Property and doesn't conform to the Property API.
789
789
790
-
Note that Multilinks are not created through its native constructor. Rather, they are created through static creator methods of Property (`Property.multilink`and`Property.unmultilink`).
791
-
792
790
##### Other Notes
793
791
- In some use cases of`Multilink` and `DerivedProperty`, the observer needs to know which Property caused the notification. One solution is to add independent listeners to each dependency and turn the DerivedProperty into a Property that is modified by each listener. Please reference https://github.com/phetsims/axon/issues/259.
794
792
@@ -817,9 +815,7 @@ ObservableArray is another common iteration of the Observer pattern. ObservableA
You may see `Emitters` used in the common code shared between simulations. Emitters are a generic event-based classthat follows the observer pattern to allow clients to subscribe (through the `addListener` method) to a single specific event.
819
817
820
-
Usually, Emitters are not needed in sim-specific code, and most of PhET's observing can be achieved with the classes outlined above.
821
-
822
-
#### Events
818
+
#### Input Events
823
819
Another form of PhET's version of the Observer pattern is through user-triggered events, such as dragging, clicking (pressing), etc. This is all done through the scenery input system.
824
820
825
821
Scenery Nodes support `FireListener`, `DragListener`, `PressListener`, etc. Listeners subscribe to when the user does a specified event, which may alter the simulation. Listeners are often passed a [SceneryEvent](https://github.com/phetsims/scenery/blob/master/js/input/SceneryEvent.js).
0 commit comments