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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e3237a0dad5569ddc2cb3d1e6837d3c03ce003d
4
- data.tar.gz: 5a0371d71ae7ea0f4e0f2bc47647055e570d8c2f
3
+ metadata.gz: 52e8be3ba802d2d3a4a0f1bdddbac59a32eea455
4
+ data.tar.gz: 6c14152e5fee498b339fe107141b0cf86aa778a3
5
5
  SHA512:
6
- metadata.gz: 30e5198ad5b05b8c07d81b75c41d91df7f94f46f7f446af8d8683f3e531c2469a7aa7a0f4733be3bf5e42852279bcc5845d50c176d95d8a87d6f3d91a0a34086
7
- data.tar.gz: 95d8af588526663ecd785e45763f54e61d58d7350dea424a6b9e78aa3be1ee0acd152fb9ba124dadbdc039ff15849718f62e95d98048442b4c479c6def498c45
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 = nil
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
- @watching = dispatcher.async do
86
- bound_result = refresh_bound if sides.include?(:bound)
87
- object_result = refresh_object if sides.include?(:object)
88
- on_bound_change(bound_result) if bound_result
89
- on_object_change(object_result) if object_result
90
- dispatcher.after(WATCH_TICK) { watch(sides) } unless @watching
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
 
@@ -1,3 +1,3 @@
1
1
  module MotionBindable
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -14,6 +14,11 @@ module MotionBindable::Strategies
14
14
  self.attribute = new || bound.call
15
15
  end
16
16
 
17
+ def unbind
18
+ @watching = false
19
+ super
20
+ end
21
+
17
22
  end
18
23
 
19
24
  end
@@ -21,6 +21,11 @@ module MotionBindable::Strategies
21
21
  on_object_change
22
22
  end
23
23
 
24
+ def unbind
25
+ object.removeObserver(self, forKeyPath: attr_name)
26
+ super
27
+ end
28
+
24
29
  end
25
30
 
26
31
  end
@@ -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({ attribute: @bound })
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
- @strategy2 = FakeStrategy.new(@object.nested, :attribute)
72
- @strategy2.bind(@bound)
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
- it 'should send unbind to all strategies' do
77
- @strategy1.should.receive(:unbind).once
78
- @strategy2.should.receive(:unbind).once
79
- @object.unbind_all
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
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: 2013-12-27 00:00:00.000000000 Z
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: