Skip to content

Default values for optional arguments #100

@willviles

Description

@willviles

Optional arguments currently don't work with default values when the argument is undefined or null. This issue has also been observed by @artemgurzhii.

// component.js
@argument(optional('string'))
foo = 'defaultValue'
{{! parent-template.hbs}}
<Component />
{{! component-template.hbs}}
{{log foo}} {{! => undefined}}

Also, setting the value of the optional argument in the component during any point of the component lifecycle does not mutate the value:

// component.js
didInsertElement () {
  super.didInsertElement(...arguments)
  this.set('foo', 'mutatedValue')
}
{{! component-template.hbs}}
{{log foo}} {{! => undefined (still)}}

This is also true when argument values are supplied to the component:

{{! parent-template.hbs}}
<Component @foo="providedValue" />
// component.js
didInsertElement () {
  super.didInsertElement(...arguments)
  this.set('foo', 'mutatedValue')
}
{{! component-template.hbs}}
{{log foo}} {{! => providedValue}}

If this is a bug, I assume it's a problem with the getter logic for optional arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions