Coder Social home page Coder Social logo

Add support for factories about typhoon HOT 4 CLOSED

appsquickly avatar appsquickly commented on August 19, 2024
Add support for factories

from typhoon.

Comments (4)

jasperblues avatar jasperblues commented on August 19, 2024

This is already supported. I'll update the documentation ASAP. Meantime take a look at:

  • (void)test_returns_component_from_factory_component
    {
    Sword* sword = [_componentFactory componentForKey:@"blueSword"];
    assertThat([sword description], equalTo(@"A bright blue sword with orange pom-poms at the hilt."));
    }

Which in the block style, is satisfied like so:

  • (id)swordFactory
    {
    return [TyphoonDefinition withClass:[SwordFactory class]];
    }
  • (id)blueSword
    {
    return [TyphoonDefinition withClass:[Sword class] initialization:^(TyphoonInitializer* initializer)
    {
    initializer.selector = @selector(swordWithSpecification:);
    [initializer injectParameterNamed:@"specification" withValueAsText:@"blue" requiredTypeOrNil:[NSString class]];
    } properties:^(TyphoonDefinition* definition)
    {
    //TODO: Fix this
    definition.factoryComponent = @"swordFactory";
    }];
    }

Ahhhhhhh. . . .. But you've just pointed out a TODO, that needs doing. You should be able to say fdefinition.factoryComponent = [self swordFactory] . . . .(currently it is the selector name in string form).

Will fix this today.

On Mar 3, 2013, at 1:47 AM, José González [email protected] wrote:

I was trying to create a Core Data stack using Typhoon and faced the following problem: I had to create the managed object model injecting the URL of the model in the initializer. The URL of the model is typically constructed this way:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CoreDataTest" withExtension:@"momd"];
As far as I know (correct me if I'm wrong) there is no way to create / inject such an object using Typhoon. I could build the main bundle object using Typhoon, but then I have no way of invoking a method on that object to get another object that gets injected in an additional object.

I think the general problem to be solved is to add support for factories: in fact the main bundle is a URL factory, using the method shown above. So maybe we could add something like this to Typhoon:

return [TyphoonDefinition withFactory:[self mainBundle] creator:^(TyphoonCreator *creator) {
creator.selector = @selector(URLForResource:withExtension:);
[creator injectParameterAt:0 withValueAsText:@"CoreDataTest" requiredTypeOrNil:[NSString class]];
[creator injectParameterAt:1 withValueAsText:@"momd" requiredTypeOrNil:[NSString class]];
}];
I've noticed I can have a workaround for this problem using type converters, creating a converter that converts the string "CoreDataTest.momd" to the required NSURL, but this would prevent the creation of a "natural" type converter from strings to NSURLs, as Typhoon only supports a converter for a given type.

What do you think? Am I missing anything?


Reply to this email directly or view it on GitHub.

from typhoon.

jasperblues avatar jasperblues commented on August 19, 2024

As of 1.1.2, you can now wire the factory with:

definition.factory = [self swordFactory];

from typhoon.

jasperblues avatar jasperblues commented on August 19, 2024

Updated the docs, but they need some more attention.

from typhoon.

jgongo avatar jgongo commented on August 19, 2024

Great!!! Thanks a lot!

from typhoon.

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.