Skip to content
Sean DeNigris edited this page Aug 13, 2018 · 8 revisions

Collection model - Add new object. This type of thing is frequently needed behind a button

add
	self new asMagritteMorph
		addButtons;
		addWindow;
		onAnswer: [ :newProject | self projects add: newProject ];
		openInWorld

Reading Fields Polymorphically

anObject readUsing: aDescription is implemented on both Object and Memento classes, so it will work in tricky situations where you may have either (e.g. container validation)

On-the-Fly Description Modification

Subclass MAAdaptiveModel. The original Magritte paper mentioned (on page 10) turning it into a Trait so it could be applied to any class

Extending Descriptions from the Outside

Let's say you have a description that you'd like to extend, but it's in a package that you can't modify. Just use the magritteDescription: annotation. For example:

MARelationDescription>>#descriptionClassesWithMorphic: description
	<magritteDescription: #descriptionClasses>
	^ description
			morphClass: MATokenCompletionMorph;
			yourself

Dynamic Options

INSERT DESCRIPTION HERE

[FEATURE]: Print-By-Descriptions

Object>>#printMagritteOn: concatenates child descriptions into a print string and can easily be used like:

MyDescribedObject>>#printOn: aStream
        self printMagritteOn: aStream

[FEATURE]: Description-Aware Lazy Inst Var Initialization

Return the current value of a field, or the default specified in the description

Usage Example

	MyDomainObject>>#getter
		^ self maLazyFromDescriptionOf: #getter

where:

	MyDomainObject>>#getterDescription
		^ MAElementDescription new
			accessor: #getter;
			default: 1;
			yourself

Bootstrapping

The TMagritteBootstrap trait in the Magritte-Bootstrap package uses the magic of DNU to handle unimplemented messages via descriptions. In other words, an unknown #phoneNumber message would return a phone number if there was a child description with a #phoneNumber selector or instVar accessor.