webtides / luna-js

MIT License
8 stars 0 forks source link

Private attributes #63

Open lukas-schardt opened 3 years ago

lukas-schardt commented 3 years ago

Currently there is no way to pass attributes to (server rendered) components that won't be serialized and passed to the client.

I think there should be a way to pass attributes to server rendered components that will be stripped from the element before being passed to the client.

<server-component #user-id="${this.currentUser}"></server-component>

We could use the `#' as the symbol for private attributes, just like it is the symbol for private class properties in javascript.

A advantage of this approach would be, if we are passing a lot of (rich) text, or maybe an object which is used to render static children, to a component, it won't be rendered inside the attributes and inside the component.

lukas-schardt commented 3 years ago

@quarkus @eddyloewen What is your opinion about this feature?

eddyloewen commented 2 years ago

I'm not sure if I understand correctly.

Is this an "attributes" vs. "properties" thing? Then I would rather suggest something like https://lit.dev/docs/templates/expressions/#property-expressions with the "." notation. With that it is clear that attributes are serialized and sent to the client but properties are only set internally and not serialized.

If not - I don't think that "private" is the right mental model for this. Isn't this again a question of the target? Like "server" vs. "client"? Although the "#" doesn't have to mean "private" - if documented correctly it can also mean "server only".

But I would still prefer the "." notation.

eddyloewen commented 1 month ago

@lukas-schardt I think I know now what you mean by "private". What you're reffering to is the reflection of properties to attributes correct? There is logic for this in element-js for example. We do reflect everything that was initially set as attributes or anything that was set to reflect from the property options.

Luna could respect that and look into the element configuration in order to determin whether it should add attributes or not. This should probably also be a mehtod in the Element Renderer factory.