motion_bindable 0.2.4 → 0.2.5
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/lib/motion_bindable/bindable.rb +1 -5
- data/lib/motion_bindable/strategy.rb +10 -7
- data/lib/motion_bindable/version.rb +1 -1
- data/lib/strategies/proc.rb +5 -0
- data/lib/strategies/ui_label.rb +5 -0
- data/spec/bindable_spec.rb +19 -12
- data/spec/strategies/proc_spec.rb +19 -3
- data/spec/strategies/ui_label_spec.rb +15 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e8be3ba802d2d3a4a0f1bdddbac59a32eea455
|
4
|
+
data.tar.gz: 6c14152e5fee498b339fe107141b0cf86aa778a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 089f88fb16423348824e9e04d3f5384e7f1cf9ced50c82779cd17cb3d3433783de8a8ec060abe40b4524375e6df3e84aff77da6b2d01db62393ae4f8ddccad89
|
7
|
+
data.tar.gz: ea79259bdcc11b2d20b75f53a4a11b95733b1691b1aab7ab2e77fb18141fd1b7b576655094befe3c3550f4f1faf6463467676f6270bb2f95e65396b042a3773c
|
@@ -6,11 +6,6 @@ module MotionBindable
|
|
6
6
|
# Allow attributes of an object to be bound to other arbitrary objects
|
7
7
|
# through unique strategies.
|
8
8
|
#
|
9
|
-
# ## One-way binding
|
10
|
-
#
|
11
|
-
# Currently bindings are only one-way, i.e change in the arbitrary object
|
12
|
-
# affects the bindable object but not vice-versa.
|
13
|
-
#
|
14
9
|
module Bindable
|
15
10
|
|
16
11
|
def bind_attributes(attrs, object = self)
|
@@ -30,6 +25,7 @@ module MotionBindable
|
|
30
25
|
end
|
31
26
|
|
32
27
|
def unbind_all
|
28
|
+
@bindings ||= []
|
33
29
|
@bindings.each { |b| b.unbind }
|
34
30
|
@bindings = []
|
35
31
|
end
|
@@ -41,7 +41,7 @@ module MotionBindable
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def unbind
|
44
|
-
@watching =
|
44
|
+
@watching = false
|
45
45
|
end
|
46
46
|
|
47
47
|
private # Methods to leave alone
|
@@ -78,16 +78,19 @@ module MotionBindable
|
|
78
78
|
sides << :object
|
79
79
|
end
|
80
80
|
|
81
|
+
@watching = true
|
81
82
|
watch(sides)
|
82
83
|
end
|
83
84
|
|
84
85
|
def watch(sides)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
dispatcher.async do
|
87
|
+
if @watching
|
88
|
+
bound_result = refresh_bound if sides.include?(:bound)
|
89
|
+
object_result = refresh_object if sides.include?(:object)
|
90
|
+
on_bound_change(bound_result) if bound_result
|
91
|
+
on_object_change(object_result) if object_result
|
92
|
+
dispatcher.after(WATCH_TICK) { watch(sides) }
|
93
|
+
end
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
data/lib/strategies/proc.rb
CHANGED
data/lib/strategies/ui_label.rb
CHANGED
data/spec/bindable_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe 'MotionBindable::Bindable' do
|
|
33
33
|
|
34
34
|
it 'passes the strategy to bind' do
|
35
35
|
@strategy.should.receive(:bind).once
|
36
|
-
@object.bind_attributes(
|
36
|
+
@object.bind_attributes(attribute: @bound)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -63,21 +63,28 @@ describe 'MotionBindable::Bindable' do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
describe '#unbind_all' do
|
66
|
-
before do
|
67
|
-
@strategy1 = FakeStrategy.new(@object, :attribute)
|
68
|
-
@strategy1.bind(@bound)
|
69
|
-
@object.bind(@strategy1)
|
70
66
|
|
71
|
-
|
72
|
-
@
|
73
|
-
@object.bind(@strategy2)
|
67
|
+
it 'can be called even if object isnt bound' do
|
68
|
+
lambda { @object.unbind_all }.should.not.raise(Exception)
|
74
69
|
end
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
context 'object is bound' do
|
72
|
+
before do
|
73
|
+
@strategy1 = FakeStrategy.new(@object, :attribute)
|
74
|
+
@strategy1.bind(@bound)
|
75
|
+
@object.bind(@strategy1)
|
76
|
+
@strategy2 = FakeStrategy.new(@object.nested, :attribute)
|
77
|
+
@strategy2.bind(@bound)
|
78
|
+
@object.bind(@strategy2)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should send unbind to all strategies' do
|
82
|
+
@strategy1.should.receive(:unbind).once
|
83
|
+
@strategy2.should.receive(:unbind).once
|
84
|
+
@object.unbind_all
|
85
|
+
end
|
80
86
|
end
|
87
|
+
|
81
88
|
end
|
82
89
|
|
83
90
|
end
|
@@ -16,12 +16,12 @@ describe 'MotionBindable::Strategies::Proc' do
|
|
16
16
|
context 'is bound' do
|
17
17
|
|
18
18
|
before do
|
19
|
-
@object.bind_attributes(
|
19
|
+
@object.bind_attributes(
|
20
20
|
attribute: proc { @bound.attribute },
|
21
21
|
nested: {
|
22
22
|
attribute: proc { @bound.attribute }
|
23
23
|
}
|
24
|
-
|
24
|
+
)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should refresh upon bind' do
|
@@ -33,12 +33,28 @@ describe 'MotionBindable::Strategies::Proc' do
|
|
33
33
|
@bound.attribute = 'updated'
|
34
34
|
wait(0.5) do
|
35
35
|
@object.attribute.should.equal 'updated'
|
36
|
+
@object.nested.attribute.should.equal 'updated'
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
40
|
+
context 'unbind is called' do
|
41
|
+
|
42
|
+
before do
|
43
|
+
@object.unbind_all
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should not longer update the attribute when the proc changes' do
|
47
|
+
@bound.attribute = 'hello'
|
48
|
+
wait(0.5) do
|
49
|
+
@object.attribute.should.not.equal 'hello'
|
50
|
+
@object.nested.attribute.should.not.equal 'hello'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
39
56
|
end
|
40
57
|
|
41
58
|
end
|
42
59
|
|
43
|
-
|
44
60
|
end
|
@@ -10,10 +10,10 @@ describe 'MotionBindable::Strategies::UILabel' do
|
|
10
10
|
context 'attribute is not set yet' do
|
11
11
|
|
12
12
|
before do
|
13
|
-
@object.bind_attributes(
|
13
|
+
@object.bind_attributes(
|
14
14
|
attribute: @label,
|
15
15
|
nested: { attribute: @label2 }
|
16
|
-
|
16
|
+
)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should update the label on change' do
|
@@ -30,10 +30,10 @@ describe 'MotionBindable::Strategies::UILabel' do
|
|
30
30
|
before do
|
31
31
|
@object.attribute = 'test'
|
32
32
|
@object.nested.attribute = 'test2'
|
33
|
-
@object.bind_attributes(
|
33
|
+
@object.bind_attributes(
|
34
34
|
attribute: @label,
|
35
35
|
nested: { attribute: @label2 }
|
36
|
-
|
36
|
+
)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should set the label on bind' do
|
@@ -48,6 +48,17 @@ describe 'MotionBindable::Strategies::UILabel' do
|
|
48
48
|
@label2.text.should.equal 'changed2'
|
49
49
|
end
|
50
50
|
|
51
|
+
context 'unbind is called' do
|
52
|
+
before do
|
53
|
+
@object.unbind_all
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should no longer update when the label changed' do
|
57
|
+
@object.attribute = 'hello'
|
58
|
+
@label.text.should.not.equal 'hello'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
51
62
|
end
|
52
63
|
|
53
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion_bindable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Kot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple data binding library for RubyMotion.
|
14
14
|
email:
|