motion_bindable 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/motion_bindable/strategy.rb +13 -16
- data/lib/motion_bindable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d4f78823ed3a1224388b7fc633d184c2b946722
|
4
|
+
data.tar.gz: a480c9b6b1c83b6e02a6189155577d27e42057ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be68505282ce2472d12ab56f3d0eb82591ede10e86e0b0e7f2684f1a11858fd115ea23b3751ab5a1aef089828e15b1bfa2c40eb275f6929e8c22484addb541bc
|
7
|
+
data.tar.gz: 85eb9ab70b26840aec2ee26fb627a87ab1904c914fbe596dde9f29d78893399b5dc56fca6da3fe7697bcff51c494a010934e31c4aa674f73ce86e89f3c3970cd
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/nathankot/motion-bindable)
|
4
4
|
[](https://codeclimate.com/github/nathankot/motion-bindable)
|
5
5
|
|
6
|
-
A simple data binding library for RubyMotion.
|
6
|
+
A simple two-way data binding library for RubyMotion.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -29,6 +29,14 @@ def application(application, didFinishLaunchingWithOptions: launch_options)
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
+
## Terminology
|
33
|
+
|
34
|
+
| Name | Definition |
|
35
|
+
| --- | --- |
|
36
|
+
| Object | Refers to the _parent_ object that can have many bindings. Usually a model of some sort. |
|
37
|
+
| Binding | The connection between an object and it's bound children. Observes and updates both sides. Represented as a `Strategy` |
|
38
|
+
| Bound | Usually an _input_ object, like a `UITextField` or a `Proc`. |
|
39
|
+
|
32
40
|
## Usage
|
33
41
|
|
34
42
|
Add `include MotionBindable::Bindable` to make an object bindable:
|
@@ -86,7 +94,7 @@ comes with MotionBindable. Take a look in `lib/motion_bindable/strategies` for
|
|
86
94
|
the available defaults. You can implement your own strategies by extending
|
87
95
|
`MotionBindable::Strategy`. Please use the existing strategies as a guideline.
|
88
96
|
|
89
|
-
###
|
97
|
+
### Default Strategies
|
90
98
|
|
91
99
|
The following strategies come with motion-bindable and are setup when
|
92
100
|
`MotionBindable::Strategies.use` is called.
|
@@ -44,7 +44,7 @@ module MotionBindable
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def unbind
|
47
|
-
@
|
47
|
+
@watching = nil
|
48
48
|
end
|
49
49
|
|
50
50
|
private # Methods to leave alone
|
@@ -70,30 +70,27 @@ module MotionBindable
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def start_listen
|
73
|
+
sides = []
|
74
|
+
|
73
75
|
if respond_to?(:start_observing_bound) then start_observing_bound
|
74
76
|
elsif respond_to?(:refresh_bound) && respond_to?(:on_bound_change)
|
75
|
-
|
77
|
+
sides << :bound
|
76
78
|
end
|
77
|
-
|
78
79
|
if respond_to?(:start_observing_object) then start_observing_object
|
79
80
|
elsif respond_to?(:refresh_object) && respond_to?(:on_object_change)
|
80
|
-
|
81
|
+
sides << object
|
81
82
|
end
|
82
|
-
end
|
83
83
|
|
84
|
-
|
85
|
-
@watch_bound = dispatcher.async do
|
86
|
-
result = refresh_bound
|
87
|
-
on_bound_change(result) if result
|
88
|
-
dispatcher.after(WATCH_TICK) { watch_bound } unless @watch_bound
|
89
|
-
end
|
84
|
+
watch(sides)
|
90
85
|
end
|
91
86
|
|
92
|
-
def
|
93
|
-
@
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
def watch(sides)
|
88
|
+
@watching = dispatcher.async do
|
89
|
+
bound_result = refresh_bound if sides.include?(:bound)
|
90
|
+
object_result = refresh_object if sides.include?(:object)
|
91
|
+
on_bound_change(bound_result) if bound_result
|
92
|
+
on_object_change(object_result) if object_result
|
93
|
+
dispatcher.after(WATCH_TICK) { watch(sides) } unless @watching
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|