Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
fix bug: self-managed rule
update readme: new article
  • Loading branch information
yulingtianxia committed Dec 14, 2017
1 parent 77b0ec5 commit 6a26062
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MessageThrottle.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MessageThrottle"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "A lightweight Objective-C message throttle and debounce library."
s.description = <<-DESC
MessageThrottle is a lightweight, simple library for controlling frequency of forwarding Objective-C messages. You can choose to control existing methods per instance or per class. It's an implementation of function throttle/debounce developed with Objective-C runtime.
Expand Down
10 changes: 4 additions & 6 deletions MessageThrottle/MessageThrottle.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ - (BOOL)applyRule:(MTRule *)rule
if (shouldApply) {
self.rules[mt_methodDescription(rule.target, rule.selector)] = rule;
mt_overrideMethod(rule.target, rule.selector);
mt_discardRuleWhenTargetDealloc(rule);
mt_configureTargetDealloc(rule);
}
}
else {
Expand Down Expand Up @@ -424,22 +424,20 @@ static void mt_executeOrigForwardInvocation(id slf, SEL selector, NSInvocation *
}
}

const void *kMTDeallocKey = &kMTDeallocKey;

static void mt_discardRuleWhenTargetDealloc(MTRule *rule)
static void mt_configureTargetDealloc(MTRule *rule)
{
if (mt_object_isClass(rule.target)) {
return;
}
else {
Class cls = object_getClass(rule.target);
MTDealloc *mtDealloc = objc_getAssociatedObject(rule.target, kMTDeallocKey);
MTDealloc *mtDealloc = objc_getAssociatedObject(rule.target, rule.selector);
if (!mtDealloc) {
mtDealloc = [MTDealloc new];
mtDealloc.rule = rule;
mtDealloc.methodDescription = mt_methodDescription(rule.target, rule.selector);
mtDealloc.cls = cls;
objc_setAssociatedObject(rule.target, kMTDeallocKey, mtDealloc, OBJC_ASSOCIATION_RETAIN);
objc_setAssociatedObject(rule.target, rule.selector, mtDealloc, OBJC_ASSOCIATION_RETAIN);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MessageThrottle is a lightweight, simple library for controlling frequency of fo
## 📚 Article

- [Objective-C Message Throttle and Debounce](http://yulingtianxia.com/blog/2017/11/05/Objective-C-Message-Throttle-and-Debounce/)
- [Associated Object and Dealloc](http://yulingtianxia.com/blog/2017/12/15/Associated-Object-and-Dealloc/)

## 🌟 Features

Expand All @@ -26,6 +27,7 @@ MessageThrottle is a lightweight, simple library for controlling frequency of fo
- [x] Support instance, class and meta class.
- [x] Support 3 modes: Throttle(Firstly), Throttle(Last) and Debounce.
- [x] Centralized management of rules.
- [x] Self-managed rules.

## 🔮 Example

Expand Down

0 comments on commit 6a26062

Please sign in to comment.