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 support for invoking an init callback on component and element construction #1855

Merged
merged 1 commit into from Nov 17, 2022

Conversation

tronical
Copy link
Member

@tronical tronical commented Nov 14, 2022

This enables imperative code to be run. To be used sparingly :-)

internal/compiler/object_tree.rs Outdated Show resolved Hide resolved
@@ -677,6 +681,7 @@ impl Element {
parent_type: ElementType,
component_child_insertion_point: &mut Option<ChildrenInsertionPoint>,
is_in_legacy_component: bool,
is_component_root_element: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you can't get that from the parent_type already

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but I don't think that works for repeated/conditional elements, where the parent type is not None.

@@ -139,6 +139,11 @@ fn perform_binding_analysis(
&(),
&mut |e, _| analyze_element(e, &mut context, reverse_aliases, diag),
);
for expr in component.setup_code.borrow().iter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to visit the setup code here.
It can't be part of a binding loop anyway, and we don't collect stats for it.

internal/compiler/passes/inlining.rs Outdated Show resolved Hide resolved
internal/compiler/tests/syntax/callbacks/init.slint Outdated Show resolved Hide resolved
@tronical
Copy link
Member Author

tronical commented Nov 16, 2022

I've pushed a much simpler implementation that allows init anywhere. This is "breaking" in the sense that it doesn't allow callback init;.

I'm uncertain if this is the right thing to do, or if it would be better to special-case this by producing a warning ("init deprecated, future blah blah") and excluding that callback from the initialisation code.

Otherwise the TODO is:

  • Fix C++ generator
  • Double check that the initialization order is sane
  • Fix model_data and index values to be up-to-date before calling init code on repeated element in native code
  • Fix model_data and index values to be up-to-date before calling init code on repeated element in repeater
  • Test that Sub { init => { .. } } is called if Sub has its own init
  • Fix warnings in generated Rust code
  • Disallow init in globals
  • Changelog
  • Documentation

@ogoffart
Copy link
Member

This is "breaking" in the sense that it doesn't allow callback init;.

Or a property "init"

But i think it's fine.
No such things on github right now: https://github.com/search?q=path%3A*.slint+init&type=code&p=2

@tronical tronical marked this pull request as ready for review November 17, 2022 08:31
@tronical tronical changed the title WIP: Add support for invoking an init callback on component construction Add support for invoking an init callback on component construction Nov 17, 2022
docs/langref.md Show resolved Hide resolved
docs/langref.md Outdated Show resolved Hide resolved
…nstruction

This enables imperative code to be run. To be used sparingly :-)
@tronical tronical changed the title Add support for invoking an init callback on component construction Add support for invoking an init callback on component and element construction Nov 17, 2022
@tronical tronical merged commit 907b581 into master Nov 17, 2022
@tronical tronical deleted the simon/init-callback branch November 17, 2022 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants