ember-decorators / ember-decorators/argument

Default values for optional arguments

Open
#100 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
30
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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

```js
// component.js
@argument(optional('string'))
foo = 'defaultValue'
```

```hbs
{{! parent-template.hbs}}

```

```hbs
{{! 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:

```js
// component.js
didInsertElement () {
super.didInsertElement(...arguments)
this.set('foo', 'mutatedValue')
}
```

```hbs
{{! component-template.hbs}}
{{log foo}} {{! => undefined (still)}}
```

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

```hbs
{{! parent-template.hbs}}

```

```js
// component.js
didInsertElement () {
super.didInsertElement(...arguments)
this.set('foo', 'mutatedValue')
}
```

```hbs
{{! component-template.hbs}}
{{log foo}} {{! => providedValue}}
```

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.