Giter Site home page Giter Site logo

Comments (7)

mdiep avatar mdiep commented on April 28, 2024

The objection to this approach is that it keeps objects alive.

from reactiveobjc.

hfossli avatar hfossli commented on April 28, 2024

Are you thinking about the caching?

- (instancetype)setNameBlock:(NSString *(^)(void))nameBlock
{
    __block NSString *cache;
    _nameBlock = [^NSString *{
        if(cache == nil)
        {
            cache = nameBlock();
        }
        return cache;
    } copy];
    return self;
}

Caching can be omitted.

from reactiveobjc.

mdiep avatar mdiep commented on April 28, 2024

foo is kept alive in your example:

- (void)testWithSignal
{
    Foo *foo = [Foo new];

    RACSignal *signal = [[RACSignal new] someOperatorWithObject:foo];
    XCTAssertTrue(foo.descriptionRequestedCount == 0, @"");
    XCTAssertEqualObjects([signal name], @"transformed using `someOperatorWithObject` with object <Foo 0xFOOBAR>");
    XCTAssertTrue(foo.descriptionRequestedCount == 1, @"");
    XCTAssertEqualObjects([signal name], @"transformed using `someOperatorWithObject` with object <Foo 0xFOOBAR>");
    XCTAssertTrue(foo.descriptionRequestedCount == 1, @"");
}

from reactiveobjc.

hfossli avatar hfossli commented on April 28, 2024

You're right. That means the convenience macro is not a good idea as each object would need to weakly captured.

And my feeling is that this is probably too cumbersome

- (instancetype)someOperatorWithObject:(NSObject *)object
{    
    @weakify(object);
    return [self setNameBlock:^NSString *{ 
        @strongify(object);
        return [NSString stringWithFormat:@"transformed using `someOperatorWithObject` with object %@", [object description]];
    }];
}

from reactiveobjc.

mdiep avatar mdiep commented on April 28, 2024

You could probably build the @weakify/@strongify into a macro that sets the name. Feel free to open a PR if you'd like to work on that.

from reactiveobjc.

hfossli avatar hfossli commented on April 28, 2024

Yeah, I could do a PR if you guys think this is a good idea. Don't want to invest time and then get it rejected if you fundamentally disagree about the concept :)

from reactiveobjc.

mdiep avatar mdiep commented on April 28, 2024

No, that seems like an acceptable approach to me.

from reactiveobjc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.