nue icon indicating copy to clipboard operation
nue copied to clipboard

New feature: Explicit attributes declaration of child components

Open ShiMeiWo opened this issue 1 year ago • 2 comments

In the current template syntax, a value is passed from a parent component to a child component using :bind , etc., but it is difficult to quickly see the name of the attribute that the child component accepts. Therefore, using the fact that the NueJS template syntax is based on the ES6 class, I would like to propose the following writing style:

<div @name="media-object" class="{ type }">
  <img src="{ img }">
  <aside>
    <h3>{ #title }</h3>
    <p>{ #format(desc) }</p>
  </aside>

  <!-- instance variables and methods -->
  <script>
    // attributes received from the parent are declared as public fields.
    // they serve the purpose of self-documentation, viewing the attributes as the API of the component.
    // default values are optional.
    type
    img = './noImage.png'
    desc = ''

    // instance variables are declared as private fields
    #title = 'Default title'

    // called when the component is created
    constructor(data) {
    }

    // also, instance methods are declared as private members
    #format(value) {
    }
  </script>

</div>

I would appreciate your opinion. Thanks!

ShiMeiWo avatar Oct 28 '23 11:10 ShiMeiWo

I think this is a great suggestion - apart from the 'optional default values' bit, which makes the declaration statements look like expressions. In this case I would prefer the more verbose type = null or type = undefined.

JensRoland avatar Oct 29 '23 15:10 JensRoland

Makes sense. I think Nue should support this. ie the instance variables get overridden by the given attributes. But I feel this is more like a best practise and not a requirement.

tipiirai avatar Oct 30 '23 07:10 tipiirai