A binding with 'NSNegateBoolean' transformer will not handle 'nil' correct #1986

Open
wants to merge 1 commit into
from

Projects

None yet

4 participants

@mrcarlberg
Member

I have no fix for this as I have a hard time figuring out how to solve this. I have only done the test case. Any help in doing this should be highly appreciated.

The corresponding working Objective-C test case is here:

- (void)testTransformValueBinding {
    NSButton *control = [[NSButton alloc] initWithFrame:CGRectZero];
    [control setButtonType:NSSwitchButton];

    NSArray *content =
    @[
     [@{ @"state": @YES } mutableCopy],
     [@{ @"state": @NO } mutableCopy],
     [@{} mutableCopy]
     ];

    NSArrayController *arrayController = [[NSArrayController alloc] initWithContent:content];

    [control bind:NSValueBinding toObject:arrayController withKeyPath:@"selection.state" options:@{ NSValueTransformerNameBindingOption: @"NSNegateBoolean" }];

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:0]];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"content[0] is negated");
    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:1]];
    STAssertEqualObjects([control objectValue], @(NSOnState), @"content[1] is negated");
    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:2]];
    STAssertEqualObjects([control objectValue], @(NSOnState), @"content[2] is negated");

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:1]];
    [control performClick:nil];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"value was changed");
    STAssertEqualObjects([content[1] valueForKey:@"state"], @YES, @"content[1] was negated after change");

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:2]];
    [control performClick:nil];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"value was changed");
    STAssertEqualObjects([content[2] valueForKey:@"state"], @YES, @"content[2] was negated after change");
}
@cappbot
Collaborator
cappbot commented Sep 12, 2013

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

@aljungberg
Member

Shouldn't NSIsNotNilTransformer be used for a value that can be nil?

@mrcarlberg
Member

Yes, it can. But now I have a bool value that I need to negate. If it is null it should be counted as false and after the transformer it should be true. This doesn't not work in Cappuccino. It does work in Cocoa as the test case shows.

@mrcarlberg
Member

I can add that the reason for not working is that when the value is null it will be a 'null marker' and transformers are not applied when the value is a 'marker'.

@ahankinson

-#new
+#needs-patch

@cappbot
Collaborator
cappbot commented May 5, 2014

Milestone: Someday. Label: #needs-patch. What's next? This issue needs a volunteer to write and submit code to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment