Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column
width15px

Column

The presentation model (PM) approach is the recommended view layer architecture for Swiz.
The goal is to remove any logic from the view and let the PM handle the view logic.
The view gets the PM injected and binds data from it and delegates all interactions (events) to the PM.

Code Block
titleMyView.mxml
borderStylesolid
<?xml version="1.0" encoding="utf-8"?>
<s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
					  xmlns:mx="library://ns.adobe.com/flex/mx" currentState="{model.currentState}">
	<fx:Script>
		<![CDATA[
			import example.model.presentation.MyPresentationModel;
			[Bindable]
			[Inject]
			public var model:MyPresentationModel;
		]]>
	</fx:Script>

	<s:layout>
		<s:VerticalLayout />
	</s:layout>

	<s:states>
		<s:State name="default" />
		<s:State name="detail" />
	</s:states>

	<s:List labelField="{model.listLabelField}" dataProvider="{model.dataProvider}" change="model.changeListIndex(event.newIndex)" />

	<s:Label includeIn="detail" text="{model.selectedTitle}" />

	<s:Button includeIn="detail" label="Edit" click="model.edit()" />

</s:SkinnableContainer>


Having no logic in the view itself also means that you only have to unit test your PM.

The PM has to be declared in the BeanProvider and the recommended way is to declare it as a Prototype so the PM will only be created (instantiated) when the corresponding view gets added to the stage.

Code Block
titleBeans.mxml
borderStylesolid


<?xml version="1.0" encoding="utf-8"?>
<swiz:BeanProvider xmlns:swiz="http://swiz.swizframework.org" xmlns:fx="http://ns.adobe.com/mxml/2009"
				   xmlns:presentation="example.model.presentation.*">

	<swiz:Prototype type="{MyPresentationModel}" />

</swiz:BeanProvider>


Column
width15%