Module: QML::Reactive::Bindable
- Included in:
- QtProperty, Property
- Defined in:
- lib/qml/reactive/bindable.rb
Defined Under Namespace
Modules: Resolver
Instance Method Summary collapse
-
#bind { ... } ⇒ Object
Sets a property binding.
- #initialize(*args, &block) ⇒ Object
- #unbind ⇒ Object
-
#value ⇒ Object
The property value.
-
#value=(new_value, unbind = true) ⇒ Object
(also: #set_value)
Sets a new value.
Instance Method Details
#bind { ... } ⇒ Object
Sets a property binding. The block is re-evaluated when any of other properties used in it is updated and the result is used as the new property value.
58 59 60 61 62 63 64 65 66 |
# File 'lib/qml/reactive/bindable.rb', line 58 def bind(&block) unbind value, sources = Resolver.eval_and_resolve(&block) set_value(value, false) @connections = sources.map do |source| fail Error, 'Recursive binding' if source == self source.changed.connect { set_value(block.call, false) } end end |
#initialize(*args, &block) ⇒ Object
5 6 7 8 |
# File 'lib/qml/reactive/bindable.rb', line 5 def initialize(*args, &block) super @connections = [] end |
#unbind ⇒ Object
68 69 70 |
# File 'lib/qml/reactive/bindable.rb', line 68 def unbind @connections.each(&:disconnect) end |
#value ⇒ Object
25 26 27 28 |
# File 'lib/qml/reactive/bindable.rb', line 25 def value touch super end |
#value=(new_value, unbind = true) ⇒ Object Also known as: set_value
Sets a new value. The old property binding is discarded.
13 14 15 16 17 18 19 20 |
# File 'lib/qml/reactive/bindable.rb', line 13 def value=(new_value, unbind = true) self.unbind if unbind unless value == new_value super(new_value) changed.emit(new_value) end new_value end |