rm-extensions 0.1.0 → 0.1.1

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: 9492c875dd1cedac32f756c747a6bb1dec24f2ac
4
- data.tar.gz: 3f98058ac2b7e195413706d586332a135ad72bad
3
+ metadata.gz: bbafb71f1715936049bc7a87a9fb2806e31069a2
4
+ data.tar.gz: 6d65f8db493d1c0a58c60ff46969256795c5d3c2
5
5
  SHA512:
6
- metadata.gz: fafe79e35d321d4999b7ebbd2a5c11addc69a42f9b74d28ab087a9ba9cb59fed73c23ae38ec6b31152dee1b4dba62da70f71d342cd8fc7259616da004c4b2db9
7
- data.tar.gz: 6a8071578eabf1f8c7404c920812693cf137b26ca4c02c1fe00f34f8d6f5750bb69b49a5aa54d4cabefaf66f4474bb750cace04cbaf54d89743a486f8999661a
6
+ metadata.gz: 91c0e8421e4e203d3bdcd3c13f49fcb92cff53ece8ab9f28751b496f1badb2d08b81e3f7a64b37520d6d0ec3ed56f9247259e351b1d205b6ab61f5974ef5f8f2
7
+ data.tar.gz: 523156ea087b13f2eea0796bf931c2f07a031519c0de8af6fe805e8f1cbd81b2b8bcb5ee5754e10bb8e78177884315d5d9abffbd34a8246930c153ff36f1494c
data/README.md CHANGED
@@ -16,13 +16,13 @@ class MyViewController < UIViewController
16
16
  rmext_observe(@model, "name") do |val|
17
17
  p "name is #{val}"
18
18
  end
19
- foo.on(:some_event) do |val|
19
+ foo.rmext_on(:some_event) do |val|
20
20
  p "some_event called with #{val.inspect}"
21
21
  end
22
22
  end
23
23
  end
24
24
  def test_trigger
25
- foo.trigger(:some_event, "hello!")
25
+ foo.rmext_trigger(:some_event, "hello!")
26
26
  end
27
27
  end
28
28
  ```
@@ -30,17 +30,16 @@ end
30
30
  Differences from BW::KVO and BW::Reactor::Eventable:
31
31
 
32
32
  - No need to include a module in the class you wish to use it on
33
- - The default is to observe and immediately fire the supplied callback
34
- - The callback only takes one argument, the new value
35
- - the object observing is not retained, and when it is deallocated, the observation
36
- will be removed automatically for you. there is typically no need to clean up
37
- and unobserve in viewWillDisappear, or similar.
38
- - the observation actually happens on a proxy object
33
+ - the observation happens on a proxy object
34
+ - KVO: The default is to observe and immediately fire the supplied callback
35
+ - KVO: The callback only takes one argument, the new value
36
+ - KVO: the object observing is not retained, and when it is deallocated, the observation
37
+ will be removed automatically for you. there is typically no need to clean up manually
39
38
 
40
39
 
41
40
  ## Accessors
42
41
 
43
- #### weak attr_accessors when you need to avoid retain-cycles:
42
+ #### weak attr_accessors:
44
43
 
45
44
  ```ruby
46
45
 
@@ -53,7 +52,6 @@ class MyViewController < UIViewController
53
52
  super.tap do
54
53
  v = MyView.alloc.initWithFrame(CGRectZero)
55
54
  view.addSubview(v)
56
- # if delegate was a normal attr_accessor, this controller could never be deallocated
57
55
  v.delegate = self
58
56
  end
59
57
  end
@@ -61,24 +59,6 @@ end
61
59
 
62
60
  ```
63
61
 
64
- ## Deallocation
65
-
66
- #### watch for an object to deallocate, and execute a callback:
67
-
68
- ```ruby
69
- def add_view_controller
70
- controller = UIViewController.alloc.init
71
- controller.rmext_on_dealloc(&test_dealloc_proc)
72
- navigationController.pushViewController(controller, animated: true)
73
- end
74
-
75
- def test_dealloc_proc
76
- proc { |x| p "it deallocated!" }
77
- end
78
-
79
- # now you can verify the controller gets deallocated by calling #add_view_controller
80
- # and then popping it off the navigationController
81
- ```
82
62
  ## Queues
83
63
 
84
64
  #### Wraps GCD:
@@ -1,3 +1,3 @@
1
1
  module RMExtensions
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/rm-extensions.rb CHANGED
@@ -8,7 +8,6 @@ Motion::Project::App.setup do |app|
8
8
  %w(
9
9
  util
10
10
  accessors
11
- deallocation
12
11
  observation
13
12
  queues
14
13
  ).reverse.each do |x|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rm-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Noon
@@ -23,7 +23,6 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - lib/motion/accessors.rb
26
- - lib/motion/deallocation.rb
27
26
  - lib/motion/observation.rb
28
27
  - lib/motion/queues.rb
29
28
  - lib/motion/util.rb
@@ -1,56 +0,0 @@
1
- module RMExtensions
2
-
3
- module ObjectExtensions
4
-
5
- module Deallocation
6
-
7
- # perform a block before +self+ will dealloc.
8
- # the block given should have one argument, the object about to be deallocated.
9
- def rmext_on_dealloc(&block)
10
- internalObject = ::RMExtensions::OnDeallocInternalObject.create("#{self.class.name}:#{object_id}", self, block)
11
- @rmext_on_dealloc_blocks ||= {}
12
- @rmext_on_dealloc_blocks[internalObject] = internalObject
13
- nil
14
- end
15
-
16
- # removes a previously added block from the deallocation callback list
17
- def rmext_cancel_on_dealloc(block)
18
- @rmext_on_dealloc_blocks ||= {}
19
- if internalObject = @rmext_on_dealloc_blocks[block]
20
- internalObject.block = nil
21
- @rmext_on_dealloc_blocks.delete(block)
22
- end
23
- nil
24
- end
25
-
26
- end
27
-
28
- end
29
-
30
- # Used internally by +rmext_on_dealloc+. The idea is this object is added to the
31
- # object we want to watch for deallocation. When the object we want to watch
32
- # is about to dealloc, this object will dealloc first, so we can execute the block.
33
- # the object it follows is kept only as a weak reference to not create
34
- # a retain cycle.
35
- class OnDeallocInternalObject
36
- attr_accessor :description, :block
37
- rmext_weak_attr_accessor :obj
38
- def self.create(description, obj, block)
39
- x = new
40
- x.description = description
41
- x.obj = obj
42
- x.block = block
43
- x
44
- end
45
- def dealloc
46
- # p "dealloc OnDeallocInternalObject #{description}"
47
- if block
48
- block.call(obj)
49
- self.block = nil
50
- end
51
- super
52
- end
53
- end
54
-
55
- end
56
- Object.send(:include, ::RMExtensions::ObjectExtensions::Deallocation)