Skip to content

ViewSynchronizer

Overview

Logic that handles the creation and disposal of model-view pairs.

This is helpful to use in cases where you've got to track model-view pairs, and you want to make sure that the view is created/removed when the corresponding model element is created/removed.

@author Agustín Vallejo @author Jonathan Olson

Class ViewSynchronizer

import { ViewSynchronizer } from 'scenerystack/scenery-phet';

Constructor

new ViewSynchronizer( container : Node, factory : ( x: Model ) => View )

Instance Methods

add( model : Model )

Adds a model element. An associated view (Node) is created and added to the scene graph.

remove( model : Model )

Removes a model element. Its associated view (Node) is removed from the scene graph and disposed.

getView( model : Model ) : View

Gets the view (Node) for a specified model element.

getViews() : View[]

Gets the views (Nodes) for all model elements.

dispose()

Removes all model elements and their associated views (Nodes).

Source Code

See the source for ViewSynchronizer.ts in the scenery-phet repository.