jeudi 26 novembre 2020

Ember required component arguments

How can I require a parameter in an ember component.

E.g.:

class MyComponent extends Component {
  get my_value() {
    return this.args.my_argument + 1
  }
}

I want the component to throw an error when the component is instantiated and not when the function is called.

The only way I can think of is like this:

class MyComponent extends Component {
  constructor(owner, args) {
    super(owner, args)
    assert(!!args.my_argument, "MyComponent requires my_argument")
  }
  ...
}

This however seems a bit tedious and does not look right :/

EDIT:

It would be even better if I could specify the type of the argument.




Aucun commentaire:

Enregistrer un commentaire