Latest 0.1.3
Homepage https://github.com/matt-holden/MFHMessageDebouncer
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation
Authors

This is an Objective-C implementation of a method debouncer. You can
read more about deboucing here.

MFHMessageDebouncer is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MFHMessageDebouncer"

Usage

You have the option of:

  1. Debouncing all messages to an object, or
  2. Debounce all messages to any object originating at a specific call
    site (not yet available in Swift):

1 (most common usage):

NSTimeInterval delayLength = 1.0;
NSMutableArray *myArray = [NSMutableArray array];

for (int i = 0; i < 3; i++) {
    [[myArray debounceWithDelay:delayLength] addObject:@(i)];
}

// One second (delayLength) later, myArray will hold a single element, the number 3.
// The `addObject:` message was only sent to myArray a single time

2: (pulled straight from the unit tests)


// Make three mutable arrays
NSArray *arrayInstances = @[[NSMutableArray new], [NSMutableArray new], [NSMutableArray new]];

NSTimeInterval delay = 1.0;
for (int i = 0; i < 3; i++) {
  // Debounce any message sent from this specific call site, regardless
  // of the receiver or message name
  [MFHDebouncedCallSite(arrayInstances[i], delay) addObject:@(i)];
}

// .... one second later, 
// Only the last object that was messaged will have received 'addObject:'
[arrayInstances[0] count] == 0;  //true
[arrayInstances[1] count] == 0;  //true
[arrayInstances[2] count] == 1;  //true
[arrayInstances[2] objectAtIndex:0] == @3;  //true

Author

Matthew Holden @MFHolden

License

MFHMessageDebouncer is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MFHMessageDebouncer",
    "version": "0.1.3",
    "summary": "Message debouncing in a syntactically sweet fashion",
    "description": "                       [[myObject debounceWithDelay:5] doSomething:@1];n                       [[myObject debounceWithDelay:5] doSomething:@2];n                       [[myObject debounceWithDelay:5] doSomething:@3];nn                       // ^ my Object only receive the final message send in this sequence,n                       // receiving `@3` for the `doSomething` argument, after a 5 second delay.nn",
    "homepage": "https://github.com/matt-holden/MFHMessageDebouncer",
    "license": "MIT",
    "authors": {
        "Matthew Holden": "[email protected]"
    },
    "source": {
        "git": "https://github.com/matt-holden/MFHMessageDebouncer.git",
        "tag": "0.1.3"
    },
    "social_media_url": "https://twitter.com/@MFHolden",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes",
    "public_header_files": "Pod/Classes/MFHMessageDebouncer.h",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This