Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow null, undefined, if and unless for strict component arguments #922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Aug 17, 2021

I am not 100% sure, but I think that this should be correct and fixes #921.

With this PR, the following would be allowed with strictComponents=true:

<PowerSelect
  @afterOptionsComponent={{if 
    @afterOptionsComponent 
    (ensure-safe-component @afterOptionsComponent) 
    null
  }}
  @afterOptionsComponent={{null}}
  @afterOptionsComponent={{undefined}}
  @afterOptionsComponent={{unless @thing (ensure-safe-component @afterOptionsComponent)}}
  @afterOptionsComponent={{ensure-safe-component @afterOptionsComponent}}
/>

Basically, it specifically allows null, undefined, ensure-safe-component, if and unless. When using if or unless, it will check if each path either returns null/undefined or a valid component. So the following will still fail:

<PowerSelect
  @afterOptionsComponent={{if @check 'string'}}
  @afterOptionsComponent={{if @check (component @afterOptionsComponent)}}
/>

I added a bunch of tests hopefully covering this well.

@ef4
Copy link
Contributor

ef4 commented Aug 17, 2021

Thanks, this seems good but haven't had a chance to fully review these changes yet.

I do want to point out that this usage:

  @afterOptionsComponent={{if 
    @afterOptionsComponent 
    (ensure-safe-component @afterOptionsComponent) 
    undefined
  }}

shouldn't be necessary because ensure-safe-component tolerates null and undefined by passing them through.

But in general, this is a nice extension to the rules system.

@mydea
Copy link
Contributor Author

mydea commented Aug 18, 2021

I do want to point out that this usage:

  @afterOptionsComponent={{if 
    @afterOptionsComponent 
    (ensure-safe-component @afterOptionsComponent) 
    undefined
  }}

shouldn't be necessary because ensure-safe-component tolerates null and undefined by passing them through.

Ah, true, the example is actually "wrong", I wanted to show it with null as fallback, which is used in power select (where it differentiates between undefined = default component, null = no component).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing optional component arguments through does not work
2 participants