Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

ViewModel

dzearing edited this page Oct 13, 2014 · 1 revision

Summary

The ViewModel class provides a base on which you can mix data in, listen for 'change' events on anything that declares it, and fire a single 'change' event when one or more things change. This allows listeners (TemplatedView subclasses) to re-evaluate their state.

Usage

In TemplatedView instances, the ViewModel class is used itself as the default view model. Calling the setData method automatically mixes in values and fires a change event if their values change, allowing the view to re-evaluate its view state.

Typically a ViewModel encapsulates the data contract for a view.

	class FooViewModel extends ViewModel {
		item: FooItem;
		
		name() {
			return this.item ? this.item.name : 'foo';
		}
	}

Methods

	constructor(data?: any)
	
	initialize()
	dispose()

	setData(data: any, forceChange)

	onInitialize()
	onDispose()
	onChange(data: any) {}

Events fired

  • change - fires when data changes are detected from within setData calls.
Clone this wiki locally