Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to mark property as required #7429

Open
jmEvoqua opened this issue Jan 22, 2025 · 2 comments
Open

Add possibility to mark property as required #7429

jmEvoqua opened this issue Jan 22, 2025 · 2 comments
Labels
a:language-slint Compiler for the .slint language (mO,bF) enhancement New feature or request rfc Request for comments: proposals for changes

Comments

@jmEvoqua
Copy link

Feature Description

It would be nice to mark properties as required, meaning they have to be set from outside. (Like in the Timer)

The use case is, that we have whole navigation trees abstracted away. And there we pipe properties through. The top level component has all properties required for the tree, which will be a lot. So it is easy to miss a property if it gets added in a subpage.

Product Impact

No response

@jmEvoqua jmEvoqua added enhancement New feature or request need triaging Issue that the owner of the area still need to triage labels Jan 22, 2025
@ogoffart ogoffart added rfc Request for comments: proposals for changes a:language-slint Compiler for the .slint language (mO,bF) and removed need triaging Issue that the owner of the area still need to triage labels Jan 23, 2025
@ogoffart
Copy link
Member

That would make sense.
I suggest something like that

export component FooBar {
    required property <int> foobar;
}

Where require is the same as in but must be set when used from Slint.
What happens when FooBar is previewed alone or is top level though? Then it won't get a value.

Does it make sense to give a default value?

// should that be an error?
required property <int> foobar: 42;

Is required the best term?

@jmEvoqua
Copy link
Author

jmEvoqua commented Jan 24, 2025

I think the option to have a default value is a must for easier development with the live viewer. But it should be limited to the live viewer, meaning a required property with a default value is still required to be set from the outside.
Maybe the placeholder approach #6113 would be a better fit here.

required is also fine for me. It is used in C# for the exact same purpose, or in typescript with a different handling/syntax.
Not saying we should copy these languages but it can be familiar to devs from these languages.

It would also be nice to have required callbacks:

export component FooBar {
    required property <int> foobar;
    required callback clicked();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-slint Compiler for the .slint language (mO,bF) enhancement New feature or request rfc Request for comments: proposals for changes
Projects
None yet
Development

No branches or pull requests

2 participants