Created
March 5, 2014 18:58
-
-
Save MrSmith33/9374082 to your computer and use it in GitHub Desktop.
one-to-one binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class IProperty | |
{ | |
// called when value changes. | |
alias PropertyChangedSignal = Signal!(FlexibleObject, Variant); | |
alias PropertyChangingSignal = Signal!(FlexibleObject, Variant*); | |
Variant value() @property; | |
Variant value(Variant) @property; | |
ref PropertyChangedSignal valueChanged() @property; | |
ref PropertyChangingSignal valueChanging() @property; | |
alias value this; | |
} | |
static void pipeTo(IProperty source, IProperty dest, Variant delegate(Variant) converter) | |
{ | |
auto handler = (FlexibleObject obj, Variant value){ | |
dest.value = converter(value); | |
}; | |
dest.value = converter(source.value); | |
source.valueChanged.connect(handler); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment