PATH  WebObjects 4.0 Documentation > What's New in WebObjects 4.0

Table of Contents Previous Section

Non-Synchronizing Components

By default, a nested component pulls all values from its parent and pushes all values to its parent before and after each phase of the request-response loop. This can lead to problems where values are being set when you don't want them set. In addition, the reusability of components is diminished if you must pre-compute everything a nested component needs before using it inside of another component.

The solution to both of these problems is non-synchronizing components. When components are not synchronized, they behave more like dynamic elements in that values are not pushed or pulled until they are needed.

To create a non-synchronizing nested component, do the following:

For example, consider a nested component named NonSyncComponent that you declare in a parent component in this way:

//parent component's .wod file
MySubcomponent : NonSyncComponent {
	stringValue = @"I'm a string!";
}
Suppose NonSyncComponent contains a WOString element that it declares in this way:

// NonSyncComponent.wod 
MyString : WOString {
	value = someStringValue;
}
If NonSyncComponent's script file looks like the following, the value that the parent bound to the stringValue attribute is pushed and pulled to WOString's value attribute whenever WOString requests it. Thus, the WOString in this NonSyncComponent displays "I'm a string!"

// NonSyncComponent.wos
- synchronizesVariablesWithBindings {
	return NO;
}

- someStringValue { 
	return [self valueForBinding:@"stringValue"];
}

- setSomeStringValue:aValue {
	[self setValue:aValue ForBinding:@"stringValue"];
}
If NonSyncComponent has no other need for someStringValue than to resolve the value attribute for its WOString, then NonSyncComponent can instead use this shorthand notation in its declarations file:

// Alternate NonSyncComponent.wod 
MyString : WOString {
	value = ^stringValue;
}
The carat (^) syntax means "use the value that my parent bound to my stringValue attribute to resolve value." This syntax is a convenience that saves you from having to always write cover methods for valueForBinding: and setValue:forBinding:. In addition to being more convenient, this syntax is often more efficient because none of your code is invoked to do either the pushing or the pulling.

Table of Contents Next Section