Function callbacks #1986
Replies: 3 comments 11 replies
-
I am usually not fond of callbacks like this. Callbacks forces function closure and this is a really advance topic. On click handling is a very common requirement and this makes closures a very complicated topic a requirement for. a very common task. I prefer "excel model". All data is already set up. If you think in Rust etc, which are no UI language, you will have a harder time using fastn. In fastn ALL DATA is UI data. Our garbage collector drops any data, our code generator elides any data that is not connected to UI. What does it mean for data to be connected to UI?
Here we have connected If So if you think in Rust, I have declared data, and data is sacrosanct, and data comes first, and UI is just some print statements, etc, then you have wrong mental model. Alternative to callbacks: mutable variable. When you are setting up UI, you have created all data for the UI, and if a UI controls some mutable data that is going to be mutated by that UI, eg by that checkbox, but that data is going to be needed by other parts of UI as well, you create a variable at a higher scope where it is available to both checkbox and "said other parts", and pass the mutable reference to checkbox, and non mutable reference to "other parts" (assuming they are not going to mutate it).
This is the idiomatic way of handling data. Not callbacks. |
Beta Was this translation helpful? Give feedback.
-
There's also this usecase that the Here's how I would think it would happen in the current fastn version (this does not work btw):
This is a
What about |
Beta Was this translation helpful? Give feedback.
-
I am having second thought about this line of reasoning. Callbacks are not required, and we should allow passing normal ftd functions to on-click. The This needs more thought on my part. |
Beta Was this translation helpful? Give feedback.
-
We have a
dropdown
component in design-system: https://preview-design-system.fifthtry.site/components/dropdown/. I think the api can be improved by adding support for callback functions.The usage:
This is a call for suggestions. I've mostly used rust syntax and I'm not too happy with it.
Beta Was this translation helpful? Give feedback.
All reactions