motion-wiretap 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 446d7bb23634641466df4e37ffa85daaac5fdc8c
4
- data.tar.gz: f7b9033df4a62d4f235b47f4d5f39e1efa0bac11
3
+ metadata.gz: 32d229b7cac40b4cc57a4ebd635fbd3769f8b502
4
+ data.tar.gz: 91cb977786be3bb50c5285085f832168af3f342c
5
5
  SHA512:
6
- metadata.gz: 17981158a67d7424e538351070ac732a7591e364c515882e176f83156f6ad850d5922bbf0754cdc1a704e089f15a15fbc676c9b58b02c381d48dc76cf8f8ed34
7
- data.tar.gz: 196a340c6afe69833db31d76f51751ede875d75d38e6e9b294fde372031a5c2de60dc17b689174dd7aea6fe07ca8d53186b9dbf192bde535b99d36fb4893fa1d
6
+ metadata.gz: f404b0770e2afdce819edc814eb07e8a878301f96515e2c3f74298a2b98d0cf1f5e12466609e2bde5330cdcc420be69df543456b6c3624429021ca1d45955ec8
7
+ data.tar.gz: 9df22ce3307342f031eeb643e760bfbb36be72046f6d2eca6218fad50f6d3c2c365d69f96d3e242dca81ab22713e0ce8ebc85e7c2d041486f1b2401f3923448f
data/README.md CHANGED
@@ -32,10 +32,12 @@ Open these side by side to see the comparison:
32
32
  Usage
33
33
  -----
34
34
 
35
- Creating a wiretap is done using the factory method `Motion.wiretap()`.
35
+ Creating a wiretap is done using the factory method `Motion.wiretap()`, also
36
+ aliased as `MW()`.
36
37
 
37
38
  ```ruby
38
- @wiretap = Motion.wiretap(obj, :property)
39
+ @wiretap = Motion.wiretap(obj, :property) # this object will notify listeners everytime obj.property changes
40
+ @wiretap = MW(obj, :property)
39
41
  ```
40
42
 
41
43
  If you want to use a more literate style, you can include the
@@ -52,29 +54,29 @@ notifications or control events.
52
54
 
53
55
  ### Let's start with something practical!
54
56
 
55
- This first example will use `motion-wiretap-polluting` methods, because that's
56
- my preferred aesthetic style, but the rest of this document will focus on the
57
- non-polluting version.
57
+ In these examples I will use all three ways of creating a Wiretap
58
+ (`MW(), Motion.wiretap(), object.wiretap`).
58
59
 
59
60
  ```ruby
60
61
  # assign the label to the text view; changes to the text view will be reflected
61
62
  # on the label.
62
- @label.wiretap(:text).bind_to(@text_view.wiretap(:text))
63
+ MW(@label, :text).bind_to(MW(@text_view, :text))
63
64
 
64
65
  # assign the attributedText of the label to the text view, doing some
65
- # highlighting in-between
66
+ # highlighting in-between.
66
67
  @label.wiretap(:attributedText).bind_to(@text_view.wiretap(:text).map do |text|
67
68
  NSAttributedString.alloc.initWithString(text, attributes: { NSForegroundColorAttributeName => UIColor.blueColor })
68
69
  end)
69
70
 
70
- # bind the `enabled` property to check on whether `username_field.text` and
71
- # `password_field.text` are blank
72
- @login_button.wiretap(:enabled).bind_to(
73
- [
74
- @username_field.wiretap(:text),
75
- @password_field.wiretap(:text),
76
- ].wiretap.combine do |username, password|
77
- username && username.length > 0 && password && password.length > 0
71
+ # This code will set the 'enabled' property depending on whether the username
72
+ # and password are not empty.
73
+ Motion.wiretap(@login_button, :enabled).bind_to(
74
+ Motion.wiretap([
75
+ Motion.wiretap(@username_field, :text),
76
+ Motion.wiretap(@password_field, :text),
77
+ ]).combine do |username, password|
78
+ # use motion-support to get the 'present?' method
79
+ username.present? && password.present?
78
80
  end
79
81
  )
80
82
  ```
@@ -82,11 +84,11 @@ end)
82
84
  ### Types of wiretaps
83
85
 
84
86
  - Key-Value Observation / KVO
85
- - Arrays (map/reduce)
87
+ - Arrays (map/reduce/combine)
86
88
  - Jobs (event stream, completion)
87
- - NSNotificationCenter
88
89
  - UIView Gestures
89
90
  - UIControl events
91
+ - NSNotificationCenter (needs specs)
90
92
 
91
93
  ### Key-Value Observation
92
94
 
@@ -94,7 +96,6 @@ end)
94
96
  class Person
95
97
  attr_accessor :name
96
98
  attr_accessor :email
97
- attr_accessor :address
98
99
  end
99
100
 
100
101
  # listen for changes
@@ -129,7 +130,7 @@ person_1.name
129
130
  # => "BOB"
130
131
 
131
132
  # bind the property of one object to the value of another, but change it using `map`
132
- wiretap = Motion.wiretap(person_1, :name).bind_to(person_2.wiretap(:name).map { |value| value.upcase })
133
+ wiretap = Motion.wiretap(person_1, :name).bind_to(Motion.wiretap(person_2, :name).map { |value| value.upcase })
133
134
  person_2.name = 'Bob'
134
135
  person_1.name # => "BOB"
135
136
  ```
@@ -6,10 +6,9 @@ module MotionWiretap
6
6
  class Signal < Wiretap
7
7
  attr :value
8
8
 
9
- def initialize(value=nil)
10
- super()
9
+ def initialize(value=nil, &block)
11
10
  @value = value
12
- trigger_changed(@value)
11
+ super(&block)
13
12
  end
14
13
 
15
14
  def next(value)
@@ -25,6 +24,13 @@ module MotionWiretap
25
24
  trigger_error(error)
26
25
  end
27
26
 
27
+ # The Signal class always sends an initial value
28
+ def listen(wiretap=nil, &block)
29
+ super
30
+ trigger_changed(@value)
31
+ return self
32
+ end
33
+
28
34
  end
29
35
 
30
36
  end
@@ -1,3 +1,7 @@
1
+ def MW(*args, &block)
2
+ Motion.wiretap(*args, &block)
3
+ end
4
+
1
5
  module MotionWiretap
2
6
 
3
7
  class Wiretap
@@ -4,10 +4,6 @@ module MotionWiretap
4
4
 
5
5
  class WiretapView < WiretapTarget
6
6
 
7
- def dummy
8
- UIButton.new.enabled = true
9
- end
10
-
11
7
  def on(recognizer, options=nil, &block)
12
8
  if recognizer
13
9
  case recognizer
@@ -1,3 +1,3 @@
1
1
  module MotionWiretap
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-wiretap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  ReactiveCocoa is an amazing system, and RubyMotion could benefit from the