rm-extensions 0.3.1 → 0.3.2
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/observation.rb +27 -1
- data/lib/motion/util.rb +42 -0
- data/lib/rm-extensions/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: 3cf1c7466015bfa9d247a7331ea115b3e2488fe2
|
4
|
+
data.tar.gz: ab4897b30918931ff43d2f78a753b37f2dcce110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1dd632b69fe168f2fa6aea6d46966b4658eae245689037b7b45bb08607266af6eb6bac8fcd0937d6fcd871efc0937cfac74b06758731d23a4a05e1e80c9139c
|
7
|
+
data.tar.gz: d259f115de70b69418eb5a1b38ff62a33d33600b9613e9223b7e855e7e814dba03a598324aac0c8fc132972f463fe1af26fbe50ef6e1568b092f4f989ff7fc29
|
data/lib/motion/observation.rb
CHANGED
@@ -34,12 +34,29 @@ module RMExtensions
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
# register a callback when an event is
|
37
|
+
# register a callback when an event is triggered on this object.
|
38
|
+
#
|
39
|
+
# `inContext` should be passed the object context that the block was originally
|
40
|
+
# created in. if you are writing the block inline, this would be self. if
|
41
|
+
# you have a more complicated situation where you are passing the block around as
|
42
|
+
# an argument from another scope or method, you should take care to also keep
|
43
|
+
# track of it's context, so you can pass it correctly here.
|
44
|
+
#
|
45
|
+
# the context is needed to properly manage memory and let the block "drop out"
|
46
|
+
# when it's context deallocates, instead of creating leaks.
|
47
|
+
#
|
38
48
|
def rmext_on(event, inContext:context, withBlock:block)
|
39
49
|
rmext_observation_proxy.on(event, inContext:context, withBlock:block)
|
40
50
|
end
|
41
51
|
|
52
|
+
# register a callback when an event is triggered on this object and remove it after it fires once
|
53
|
+
# see `#rmext_on` for notes about `inContext`
|
54
|
+
def rmext_once(event, inContext:context, withBlock:block)
|
55
|
+
rmext_observation_proxy.once(event, inContext:context, withBlock:block)
|
56
|
+
end
|
57
|
+
|
42
58
|
# remove a specific callback for an event on this object
|
59
|
+
# see `#rmext_on` for notes about `inContext`
|
43
60
|
def rmext_off(event, inContext:context, withBlock:block)
|
44
61
|
if @rmext_observation_proxy
|
45
62
|
@rmext_observation_proxy.off(event, inContext:context, withBlock:block)
|
@@ -225,6 +242,15 @@ module RMExtensions
|
|
225
242
|
nil
|
226
243
|
end
|
227
244
|
|
245
|
+
def once(event, inContext:context, withBlock:block)
|
246
|
+
block.weak!
|
247
|
+
once_block = lambda do |opts|
|
248
|
+
off(event, inContext:context, withBlock:once_block)
|
249
|
+
block.call(opts)
|
250
|
+
end
|
251
|
+
on(event, inContext:context, withBlock:once_block)
|
252
|
+
end
|
253
|
+
|
228
254
|
def off_all
|
229
255
|
@events.removeAllObjects
|
230
256
|
end
|
data/lib/motion/util.rb
CHANGED
@@ -8,6 +8,48 @@ module RMExtensions
|
|
8
8
|
@debug = bool
|
9
9
|
end
|
10
10
|
|
11
|
+
# LongTask encapsulates beginBackgroundTaskWithExpirationHandler/endBackgroundTask:
|
12
|
+
#
|
13
|
+
# RMExtensions::BackgroundTask.new("my long task") do |task|
|
14
|
+
# do_something_long
|
15
|
+
# task.end!
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# RMExtensions::BackgroundTask.new("my long task") do |task|
|
19
|
+
# do_something_long_async do
|
20
|
+
# # later this long task finishes...
|
21
|
+
# task.end!
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
class LongTask
|
26
|
+
attr_accessor :bgTask, :desc
|
27
|
+
|
28
|
+
# RMExtensions::BackgroundTask.new("my long task") { |task| task.end! }
|
29
|
+
def initialize(desc=nil, &block)
|
30
|
+
@desc = desc
|
31
|
+
@bgTask = UIApplication.sharedApplication.beginBackgroundTaskWithExpirationHandler(lambda do
|
32
|
+
if ::RMExtensions.debug?
|
33
|
+
p "ERROR: #{self.inspect} #{@desc} didn't call #end! in time!"
|
34
|
+
end
|
35
|
+
UIApplication.sharedApplication.endBackgroundTask(@bgTask)
|
36
|
+
end.weak!)
|
37
|
+
block.call(self)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def end!
|
42
|
+
if ::RMExtensions.debug?
|
43
|
+
p "SUCCESS: #{self.inspect} #{@desc} ended successfully."
|
44
|
+
end
|
45
|
+
if @bgTask != UIBackgroundTaskInvalid
|
46
|
+
UIApplication.sharedApplication.endBackgroundTask(@bgTask)
|
47
|
+
@bgTask = UIBackgroundTaskInvalid
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
11
53
|
module ObjectExtensions
|
12
54
|
|
13
55
|
module Util
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rm-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Noon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extensions and helpers for dealing with various areas of rubymotion
|
14
14
|
email:
|