Using the built-in typhoon property in another definition

I have a problem with Typhoon map. I have an assembly that will build my data model:

- (DataModel *)dataModel {
    return [TyphoonDefinition withClass:[DataModel class]];
}

      

Now I want to collect all my view models. In one definition, I need to decide if the password has already been set by the user. This information is stored in the data model. So my definition looks like this:

- (id)passViewModel {
    return [TyphoonDefinition withClass:[PasscodeViewModel class] configuration:^(TyphoonDefinition *definition) {
        [definition useInitializer:@selector(initwithType:) parameters:^(TyphoonMethod *initializer) {
            NSNumber *type = [self.modelAssembly dataModel] isPasscodeSet ? @(TypeReturning) : @(TypeNew);
            [initializer injectParameterWith:type];
        }];
    }];
}

      

The problem is that when definitions are activated, dataModel is TyphoonDefinition, not DataModel.

Is there any method that can let me get the value of the dataModel property?

EDIT:

As per the answer below, my assembly looks like this:

- (UIViewController *)passcodeViewController {
    return [TyphoonDefinition withOption:[(id)[self.modelAssembly dataModel] property:@selector(isPasscodeSet)]
                                     yes:[self passcodeViewController:@(TypeReturning)]
                                      no:[self passcodeViewController:@(TypeNew)]];
}

- (UIViewController *)passcodeViewController:(NSNumber *)entryType {
    return [TyphoonDefinition withClass:[PasscodeViewController class] configuration:^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(entryType) with:entryType];
        [definition injectProperty:@selector(viewModel) with:[self.viewModelsAssembly passcodeViewModel:entryType]];
    }];
}

      

I am using "passcodeViewController" as typhoon key in storyboard. Unfortunately the viewModel and entryType I am trying to enter is nil.

+3


source to share


1 answer


You are right, an assembly can be active or inactive, so it is not designed to do what you would like to do. Therefore, there is a special function for your use case called Typhoon Option Matcher .

You can return one definition or another based on the start of another object in an (activated) assembly or runtime argument. Example:



- (id)passViewModel
{
    return [TyphoonDefinition withOption:[(id)[self.modelAssembly dataModel] 
        property:@selector(isPasscodeSet)]
        yes:[self passViewModelWithType:@(TypeReturning)] 
        no:[self passViewModelWithType:@(TypeNew)]];
}

- (id)passViewModelWithType:(NSNumber *)type
{
    return [TyphoonDefinition withClass:[PasscodeViewModel class] 
      configuration:^(TyphoonDefinition *definition) {
        [definition useInitializer:@selector(initwithType:) 
          parameters:^(TyphoonMethod *initializer) {
            [initializer injectParameterWith:type];
        }];
    }];
}

      

Does this suit your needs? Perhaps you can combine this with a factory definition .

+2


source







All Articles