Class: Glimmer::DataBinding::WidgetBinding
- Inherits:
-
Object
- Object
- Glimmer::DataBinding::WidgetBinding
- Includes:
- Glimmer, Observable, Observer
- Defined in:
- lib/glimmer/data_binding/widget_binding.rb
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
Instance Method Summary collapse
- #call(value) ⇒ Object
- #evaluate_property ⇒ Object
-
#initialize(widget, property, translator = nil, sync_exec: false, async_exec: false) ⇒ WidgetBinding
constructor
A new instance of WidgetBinding.
Methods included from Glimmer
Constructor Details
#initialize(widget, property, translator = nil, sync_exec: false, async_exec: false) ⇒ WidgetBinding
Returns a new instance of WidgetBinding.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/glimmer/data_binding/widget_binding.rb', line 35 def initialize(, property, translator = nil, sync_exec: false, async_exec: false) = @property = property @translator = translator || proc {|value| value} #TODO check on this it doesn't seem used @sync_exec = sync_exec @async_exec = async_exec if .respond_to?(:on_widget_disposed) . do |dispose_event| unregister_all_observables end end end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
34 35 36 |
# File 'lib/glimmer/data_binding/widget_binding.rb', line 34 def property @property end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
34 35 36 |
# File 'lib/glimmer/data_binding/widget_binding.rb', line 34 def end |
Instance Method Details
#call(value) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/glimmer/data_binding/widget_binding.rb', line 49 def call(value) converted_value = translated_value = @translator.call(value) update_operation = lambda do if .respond_to?(:disposed?) && .disposed? unregister_all_observables return end .set_attribute(@property, converted_value) unless evaluate_property == converted_value end if @sync_exec || Config.auto_sync_exec? && Config.require_sync_exec? SWT::DisplayProxy.instance.sync_exec(&update_operation) elsif @async_exec SWT::DisplayProxy.instance.async_exec(&update_operation) else update_operation.call end end |
#evaluate_property ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/glimmer/data_binding/widget_binding.rb', line 68 def evaluate_property if .respond_to?(:disposed?) && .disposed? unregister_all_observables return end read_operation = lambda do .get_attribute(@property) end if @sync_exec || Config.auto_sync_exec? && Config.require_sync_exec? SWT::DisplayProxy.instance.sync_exec(&read_operation) elsif @async_exec SWT::DisplayProxy.instance.async_exec(&read_operation) else read_operation.call end end |