WAModelProxy


Seaside-Utilities

Comment:

I am a fake object that can be interposed between the real model object and the client, so that the data can be validated or collected before commiting to the real model.

If you have a model instance like

	model := WAStoreAddress new.
	model street: 'Rathausgasse 34'.

create a model proxy by evaluating the following code:

	proxy := WAModelProxy on: model.
	
Then use the accessors of the proxy as you would do with your model:

	proxy country: 'Switzerland'.
	proxy street -> 'Rathausgasse 34'
	...
	
To propagate the values into your model send #commit :

	proxy commit.
	model country -> 'Switzerland'

Hierarchy:

ProtoObject
Object
WAModelProxy

Summary:

instance variables:

cache model

methods:

instance class
accessing forwarding initializing as yet unclassified

Detail:

instance variables:

cache
inferredType:
UndefinedObject
model
inferredType:
UndefinedObject

instance methods:

accessing
model

	^ model

forwarding
commit

	cache keysAndValuesDo:
		[:key :value |
		self performRealWrite: key with: value].

	cache _ Dictionary new.
doesNotUnderstand: aMessage

	^ aMessage selector isUnary
		ifTrue: [self performRead: aMessage selector]
		ifFalse:
			[(aMessage selector isKeyword and: [aMessage arguments size = 1])
				ifTrue: [self performWrite: aMessage selector allButLast with: aMessage argument]
				ifFalse: [super doesNotUnderstand: aMessage]]
name

	^ model name
performRead: aSymbol

	^ cache at: aSymbol ifAbsent: [model perform: aSymbol]
performRealWrite: aSymbol with: anObject

	model perform: (aSymbol,':') asSymbol with: anObject
performWrite: aSymbol with: anObject

	cache at: aSymbol put: anObject
value

	^ model value

initializing
setModel: anObject

	model _ anObject.
	cache _ Dictionary new.

class methods:

as yet unclassified
on: anObject

	^ self new setModel: anObject

^top


- made by Dandelion -