Mixin: SC.DelegateSupport

Support methods for the Delegate design pattern.

The Delegate design pattern makes it easy to delegate a portion of your application logic to another object. This is most often used in views to delegate various application-logic decisions to controllers in order to avoid having to bake application-logic directly into the view itself.

The methods provided by this mixin make it easier to implement this pattern but they are not required to support delegates.

The Pattern

The delegate design pattern typically means that you provide a property, usually ending in "delegate", that can be set to another object in the system.

When events occur or logic decisions need to be made that you would prefer to delegate, you can call methods on the delegate if it is set. If the delegate is not set, you should provide some default functionality instead.

Note that typically delegates are not observable, hence it is not necessary to use get() to retrieve the value of the delegate.

Defined in: delegate_support.js

Since:
SproutCore 1.0

Class Methods

Class Method Detail

delegateFor(methodName, delegate)

Selects the delegate that implements the specified method name. Pass one or more delegates. The receiver is automatically included as a default.

This can be more efficient than using invokeDelegateMethod() which has to marshall arguments into a delegate call.

Parameters:
methodName String
delegate Object...
one or more delegate arguments
Returns:
Object
delegate or null
getDelegateProperty(key, delegate)

Search the named delegates for the passed property. If one is found, gets the property value and returns it. If none of the passed delegates implement the property, search the receiver for the property as well.

Parameters:
key String
the property to get.
delegate Object
one or more delegate
Returns:
Object
property value or undefined
invokeDelegateMethod(delegate, methodName, args...)

Invokes the named method on the delegate that you pass. If no delegate is defined or if the delegate does not implement the method, then a method of the same name on the receiver will be called instead.

You can pass any arguments you want to pass onto the delegate after the delegate and methodName.

Parameters:
delegate Object
a delegate object. May be null.
methodName String
a method name
args... Object... Optional
any additional arguments
Returns:
Object
value returned by delegate
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)