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 +4 -4
- data/README.md +20 -19
- data/lib/motion-wiretap/all/signal.rb +9 -3
- data/lib/motion-wiretap/all/wiretap.rb +4 -0
- data/lib/motion-wiretap/ios/wiretap_ios.rb +0 -4
- data/lib/motion-wiretap/version.rb +1 -1
- 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: 32d229b7cac40b4cc57a4ebd635fbd3769f8b502
|
4
|
+
data.tar.gz: 91cb977786be3bb50c5285085f832168af3f342c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
56
|
-
|
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
|
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
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
[
|
74
|
-
|
75
|
-
|
76
|
-
].
|
77
|
-
|
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(
|
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
|
-
|
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
|
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.
|
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-
|
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
|