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

Docs: Reactivity #7266

Merged
merged 5 commits into from
Jan 6, 2025
Merged

Docs: Reactivity #7266

merged 5 commits into from
Jan 6, 2025

Conversation

NigelBreslaw
Copy link
Member

No description provided.

@NigelBreslaw NigelBreslaw requested a review from tronical January 3, 2025 14:43
@NigelBreslaw
Copy link
Member Author

Maybe Monday have a call about this and hash out if that react.js section should go in and how it could be better refined? Thinking is that a ton of people are familiar with React and this would help them understand Slint and be less confused by it. It also intentionally dunks on some of the issues in React that catch out all beginners. I should also add in a section on 'useEffect' and how to manage side effects and how Slint is also much simpler there.
image

Comment on lines 11 to 13
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.
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Title caps here

Suggested change
### 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Comment on lines 23 to 24
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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'

Comment on lines 65 to 67
## 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## 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.

Comment on lines 77 to 78
## Property Expressions
Expressions can vary in complexity:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## Property Expressions
Expressions can vary in complexity:
## Property Expressions
Expressions can vary in complexity:

tronical and others added 2 commits January 6, 2025 16:24
Co-authored-by: Nigel Breslaw <NigelBreslaw@users.noreply.github.com>
@NigelBreslaw NigelBreslaw merged commit b5ecd82 into master Jan 6, 2025
37 checks passed
@NigelBreslaw NigelBreslaw deleted the nigel/reactivity-docs branch January 6, 2025 16:22
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.

2 participants