-
Notifications
You must be signed in to change notification settings - Fork 635
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
Docs: Reactivity #7266
Docs: Reactivity #7266
Conversation
Slint differs from React.js in several key ways: | ||
|
||
First there is no web browser as part of Slint to render the UI. There is no DOM or shadow DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The colon suggest that there will be a list of ways, but.... there isn't. If the list is supposed to be the following headings, how about: "Slint differs from React.js in several key ways. The following sections discuss these differences."
|
||
First there is no web browser as part of Slint to render the UI. There is no DOM or shadow DOM. | ||
|
||
### Component life cycle management |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title caps here
### Component life cycle management | |
### Component Life Cycle Management |
|
||
React.js has a model where on a state change a component is destroyed and recreated. By default this will | ||
also include the destruction of all child components of an element and these then all need to be recreated. | ||
To manage performance careful use of useMemo and useCallback are needed to avoid unnecessary re-renders. Even |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To manage performance careful use of useMemo and useCallback are needed to avoid unnecessary re-renders. Even | |
To manage performance, careful use of `useMemo()` and `useCallback()` are needed to avoid unnecessary re-renders. Even |
Slint is much simpler. Components update, but they are not destroyed and recreated. There is no equivlant of | ||
useMemo and useCallback as they are unnecessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slint is much simpler. Components update, but they are not destroyed and recreated. There is no equivlant of | |
useMemo and useCallback as they are unnecessary. | |
Slint is much simpler: Components update, but they are not destroyed and recreated. There is no equivlant of | |
`useMemo()` and `useCallback()` as they are unnecessary. |
|
||
### State | ||
|
||
React.js refers to properties that update and re-render the component as state. They are opt in and by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React.js refers to properties that update and re-render the component as state. They are opt in and by | |
React.js refers to properties that update and re-render the component as state. They are opt-in and by |
be directly accessed and must be updated via setCount. | ||
|
||
The counter button is then used to update the count property and to ensure it's correctly updated must rely | ||
on the 'currentCount' value returned by setCount is used to update the values. As using `setCount(count + 1)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the 'currentCount' value returned by setCount is used to update the values. As using `setCount(count + 1)` | |
on the `currentCount` value returned by `setCount()` is used to update the values. As using `setCount(count + 1)` |
can cause issues in more complex scenarios where the state is updated later. | ||
|
||
While the Slint example may not look much simpler it does the same job and has less gotchas. As everything | ||
in Slint is reactive by default the property is declared in one single way. The language has strong types and for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Slint is reactive by default the property is declared in one single way. The language has strong types and for | |
in Slint is reactive by default, the property is declared in one single way. The language has strong types and for |
} | ||
``` | ||
|
||
As the name suggests Reactivity is all about parts of the user interface automatically updating or 'reacting' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the name suggests Reactivity is all about parts of the user interface automatically updating or 'reacting' | |
As the name suggests, reactivity is all about parts of the user interface automatically updating or 'reacting' |
## Performance | ||
From a performance perspective Slint works out what properties are changed. It then finds all the expressions | ||
that depend on that value. These dependencies are then re-evaluated based on the new values and the UI will update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Performance | |
From a performance perspective Slint works out what properties are changed. It then finds all the expressions | |
that depend on that value. These dependencies are then re-evaluated based on the new values and the UI will update. | |
## Performance | |
From a performance perspective, Slint works out what properties are changed. It then finds all the expressions | |
that depend on that value. These dependencies are then re-evaluated based on the new values and the UI updates. |
## Property Expressions | ||
Expressions can vary in complexity: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Property Expressions | |
Expressions can vary in complexity: | |
## Property Expressions | |
Expressions can vary in complexity: |
Co-authored-by: Nigel Breslaw <NigelBreslaw@users.noreply.github.com>
No description provided.