Updater:
Filter:
crucial-library/Classes (extension) | Libraries > crucial > GUI

Updater
ExtensionExtension

simple MVC utility; calls an update handler when the model changes

Description

A simple utility object that adds itself as a dependant on a model and calls the handler whenever the model is changed.

An Updater can be used to implement a simple Model-View-Controller architecture in situations where a full blown controller class is not needed.

It adds itself as a dependant to the model. When the model is issued a .changed message (after its state has been changed in some way) all of its dependants, including the Updater are sent the .update message. The Updater class then simply evalutes the updateFunction

Note: SimpleController isn't really a full controller. Its the exact same thing as this (and was written after Updater). A controller mediates in both directions between view and model, and these classes are simple updaters that just update views. ObjectGui is more of a proper controller in that it knows the model and the view(s) and mediates between them.

Class Methods

.new

Arguments:

model
updateFunc

Instance Methods

.model

.updateFunc

.init

.update

Arguments:

... args

.remove

.removeOnClose

Arguments:

layout

.findWindow

Arguments:

layout

Examples

The updater adds itself as a dependant to the model, so its important to at some point tell the updater to remove itself (as a dependant). Otherwise it will stay in the model's dependant dictionary and will not get garbage collected. It will also continue to respond to update messages. If the window has closed this means it will try to change views that no longer exist and you will get errors.

tell the layout to .remove this updater when the layout and windows close :

Update the client of messages from server

The commonly used NodeWatcher class watches server notifications and issues .changed messages to the Node objects. Updater can be used to fire an updateFunction

model - the node which you want to receive server notifications for. updateFunction -

This could also be done using SimpleController, a related class that assumes that the second argument will be a symbol.