Giter Site home page Giter Site logo

Comments (10)

jwilling avatar jwilling commented on March 29, 2024

The proxy looks fantastic. If I had a choice between the two, I'd rather go with the proxy and suffer the loss of not being able to use it with non-object properties.

However, would it be impractical to offer both? Subscripting primarily for scalars, and proxies for objects?

from reactivecocoa.

jspahrsummers avatar jspahrsummers commented on March 29, 2024

I like the proxy much less now that I realize subscribables would always have to be cast. I think I would honestly rather see them wrapped in a dummy object made specifically for this purpose, like:

self.titleLabel.rac.textColor = someSubscribable.propertySomethingOrOther;

Where the subscribable's property would simply return id.

Can go you into more detail about how exactly the keyed subscripting works?

from reactivecocoa.

joshaber avatar joshaber commented on March 29, 2024

@jspahrsummers Yeah I agree the cast is weak sauce :(

The keyed subscripting works something like:

#define RAC(keypath) self[RAC_KEYPATH_SELF(keypath)]

- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
    [self rac_deriveProperty:(NSString *) key from:obj];
}

RAC(self.blah.thing) = subscribable;

The really annoying bit is that the compiler has to be able to see the definition of -setObject:forKeyedSubscript: otherwise it won't compile. So we can't just inject it at runtime.

from reactivecocoa.

jspahrsummers avatar jspahrsummers commented on March 29, 2024

@joshaber So that wouldn't work for objects that aren't relative to self? I don't know – the keyed subscripting seems pretty picky, and probably not worth it.

from reactivecocoa.

joshaber avatar joshaber commented on March 29, 2024

@jspahrsummers Well, you could imagine a version that does:

#define RAC_OBJ(obj, keypath) obj[RAC_KEYPATH(obj, keypath)]

But that object would need to to implement -setObject:forKeyedSubscript:.

Honestly, I don't really care much about that case. The case I'm specifically thinking of is UI where there are a lot of values derived from a few basic values, most/all of which are on the class itself.

from reactivecocoa.

andymatuschak avatar andymatuschak commented on March 29, 2024

Wait, couldn't you make the proxy-bounce situation way nicer by defining rac to return instancetype? Then you wouldn't have to cast. Also, you could totally make it work with non-object properties.

from reactivecocoa.

andymatuschak avatar andymatuschak commented on March 29, 2024

Ah, wait, totally misunderstood the problem; nevermind. I've got nothing.

from reactivecocoa.

joshaber avatar joshaber commented on March 29, 2024

Actually I think there's probably a way to make the keyed subscripting version more generic. I'll give a try.

The proxy bounce is really cool since it lets you pass in a subscribable in the place of a normal object but maybe there's a better / more specific way to surface that.

from reactivecocoa.

jspahrsummers avatar jspahrsummers commented on March 29, 2024

Also, what happens if you proxy bounce on a RACSubscribable property? :trollface:

Does it have to be a subscribable of subscribables? How would it know?

from reactivecocoa.

joshaber avatar joshaber commented on March 29, 2024

That linked PR adds the subscripting-abusive assignment. It's a little more abusive but it works without needing the class to implement -setObject:forKeyedSubscript:.

@jspahrsummers I'm pretty sure the universe implodes. Pretty sure.

from reactivecocoa.

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.