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

feat: add documentation #8

Merged
merged 82 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
eb8ed1f
Add documentation
manuel-plavsic Jan 26, 2025
e565dfa
Rename file
manuel-plavsic Jan 26, 2025
ae0b741
Rename alternatives to miscellaneous
manuel-plavsic Jan 26, 2025
937dbf2
Improve docs
manuel-plavsic Jan 26, 2025
22780df
remove file prefixes
manuel-plavsic Jan 26, 2025
38222a0
Make small adjustments
manuel-plavsic Jan 26, 2025
9825b21
Make small correction
manuel-plavsic Jan 26, 2025
1009940
docs: updates
nank1ro Jan 27, 2025
2d13117
docs: add basic example
nank1ro Jan 27, 2025
ea7554e
docs: update sentence
nank1ro Jan 27, 2025
780c9ed
Add Installing page
manuel-plavsic Jan 27, 2025
af99e54
Reframe sentence
manuel-plavsic Jan 27, 2025
dd57382
Remove service_injection example
manuel-plavsic Jan 27, 2025
bb1a4aa
Prepare all examples
manuel-plavsic Jan 27, 2025
d0683b2
Fix typo
manuel-plavsic Jan 27, 2025
b4cfd62
Merge branch 'main' into feat/documentation
nank1ro Jan 27, 2025
2be31b9
Merge branch 'main' into feat/documentation
nank1ro Jan 27, 2025
917a6c7
docs: auto route
nank1ro Jan 27, 2025
4d19ab9
docs: update
nank1ro Jan 27, 2025
3deeb9e
docs: add file structure to bloc
nank1ro Jan 27, 2025
497a778
docs: use link card for source code
nank1ro Jan 27, 2025
cf00e9a
docs: update installing
nank1ro Jan 27, 2025
f3e2eda
docs: add empty line
nank1ro Jan 27, 2025
dd03b50
docs: solidart
nank1ro Jan 27, 2025
d7afcf3
Mention that global state solutions usually use extra objects to mana…
manuel-plavsic Jan 27, 2025
18fe128
Make small corrections
manuel-plavsic Jan 27, 2025
0aca5b0
Make small improvements
manuel-plavsic Jan 27, 2025
b588122
Refine bloc example
manuel-plavsic Jan 28, 2025
056fd32
docs: add example deps
nank1ro Jan 28, 2025
56d8d9a
docs: add dependency
nank1ro Jan 28, 2025
1afbffe
docs: authors
nank1ro Jan 28, 2025
15486af
docs: update bio
nank1ro Jan 28, 2025
a5205d1
docs: author card add social links
nank1ro Jan 28, 2025
7caac1d
docs: update
nank1ro Jan 28, 2025
790aa24
docs: graphical representation of provider scope
nank1ro Jan 28, 2025
aa0a563
docs: update provider scope graph
nank1ro Jan 28, 2025
195fbe9
docs: add provider scope exception
nank1ro Jan 28, 2025
95286e5
docs: theme image
nank1ro Jan 28, 2025
8057b0d
Improve authors section
manuel-plavsic Jan 28, 2025
50f5df6
Improve my own introduction
manuel-plavsic Jan 28, 2025
df7f25b
Improve authors
manuel-plavsic Jan 28, 2025
ab170c4
Small correction
manuel-plavsic Jan 28, 2025
1fe11be
Improve main page title and description
manuel-plavsic Jan 28, 2025
80492d8
Move author section to the end but also add link in index
manuel-plavsic Jan 28, 2025
78ab6bd
docs: add provider scope portal images
nank1ro Jan 28, 2025
95b43ca
docs: update authors
nank1ro Jan 28, 2025
4afd23e
docs: fix typo
nank1ro Jan 28, 2025
a0f049f
docs: add how providers are found graph
nank1ro Jan 28, 2025
958979e
docs: add note about big o notation
nank1ro Jan 28, 2025
af5c2e3
Make changes
manuel-plavsic Jan 28, 2025
f2c6692
Merge branch 'main' into feat/documentation
nank1ro Jan 28, 2025
7369695
Rename to Provider Retrieval Process
manuel-plavsic Jan 28, 2025
dfd6f7b
Add warnings
manuel-plavsic Jan 28, 2025
4b3daf8
Add comma
manuel-plavsic Jan 28, 2025
7bcf2e6
Fix typo
manuel-plavsic Jan 28, 2025
c246e41
Use notes and tips in testing and make other small improvements
manuel-plavsic Jan 28, 2025
9e64e67
Add example heading inside modals.mdx
manuel-plavsic Jan 28, 2025
5cacd72
Add two example headings to reactivity.md
manuel-plavsic Jan 28, 2025
e86f493
Reframe sentence
manuel-plavsic Jan 28, 2025
cca9c91
Rename heading in index
manuel-plavsic Jan 28, 2025
d859d6f
Clarify comment in reactivity.md
manuel-plavsic Jan 28, 2025
90c3c29
Do not capitalize "providers"
manuel-plavsic Jan 28, 2025
3f7108a
Remove unnecessary parts and make some fixes.
manuel-plavsic Jan 28, 2025
eb703d4
Make improvements to scoped-di.mdx
manuel-plavsic Jan 28, 2025
ec7a97d
Fix typos and reframe some sentences.
manuel-plavsic Jan 29, 2025
e79d1d8
Make small adjustment
manuel-plavsic Jan 29, 2025
0725865
Fix headings
manuel-plavsic Jan 29, 2025
a2f3ef9
Fix other headings
manuel-plavsic Jan 29, 2025
78996c3
Reframe text and change its order
manuel-plavsic Jan 29, 2025
17bc916
Simplify sentence in authors.mdx
manuel-plavsic Jan 29, 2025
986a923
docs: fix import
nank1ro Jan 29, 2025
17c6959
docs: fix typos
nank1ro Jan 29, 2025
aafce59
docs: fix variablee not useed
nank1ro Jan 29, 2025
968173c
Merge branch 'main' into feat/documentation
nank1ro Jan 29, 2025
416beaf
docs: preferences example
nank1ro Jan 29, 2025
ae06873
docs: preferences
nank1ro Jan 29, 2025
ddcff31
docs: immutability
nank1ro Jan 29, 2025
70c25cf
docs: remove prefixes from code title
nank1ro Jan 29, 2025
2d82a9c
docs: update var name in immutability
nank1ro Jan 29, 2025
4cc17de
Make improvements
manuel-plavsic Jan 29, 2025
d604538
fix typo
manuel-plavsic Jan 29, 2025
14894aa
Change from examples to single example in preferences.mdx
manuel-plavsic Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/src/content/docs/core/immutability.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Immutability
description: Learn the providers immutability
description: Learn how immutability impacts Disco providers.
---

import { Aside } from '@astrojs/starlight/components';
Expand Down Expand Up @@ -75,14 +75,17 @@ class _MainAppState extends State<MainApp> {
The example renders `The counter is 0`. After the user presses the `FloatingActionButton`, the counter is incremented, but the UI does not update.
This is because the provider is immutable, and the instance of the provider is not updated. In other words, the `counterProvider` is created only the first time and it still provides the initial instance.

You may be sceptical about the immutability of providers, but be sure this is a nice thing.
It helps to avoid bugs and makes the application more predictable.
You may be skeptical about the immutability of providers, but it is actually a good thing.
It helps avoid bugs and makes the application more predictable.

The typical usage for a provider is to provide a value for a specific page or widget.
When the Page or Widget is disposed, the provider is also disposed, and the value is no longer available.
When the page or widget is disposed, the provider gets also disposed, and the value is no longer available.
When the Page is opened again, a new instance of the provider is created, and the value is provided again.

There is one way to force the recreation of a provider, _which I discourage_, but can be used if you know what you're doing.
### Force the recreation of a provider

There is one way to force the recreation of a provider, _which we discourage_, but can be used if you know what you are doing.

```dart {2}
ProviderScope(
key: ValueKey(counter),
Expand All @@ -93,7 +96,8 @@ ProviderScope(
)
```

This code destroys completely the widget tree and recreates it.
The provider creation is perfomed inside the `ProviderScope` widget and causes the recreation of the provider.
As soon as you change the key of the `ProviderScope`, the old `ProviderScope` is disposed and disposes all the providers inside it.
Then a new `ProviderScope` is created and all the providers are created again.
When changing a key, the widget subtree gets regenerated.
The provider recreation is performed inside the `ProviderScope` widget. What exactly happens is the following:

1. The old `ProviderScope` is disposed, which disposes of all the providers inside it.
2. A new `ProviderScope` is created and all the providers are created again.
2 changes: 1 addition & 1 deletion docs/src/content/docs/core/scoped-di.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ In full example below, we are going to inject the two providers above with `numb
</Aside>

<Aside>
Users transitioning from Provider or Riverpod should note an important distinction: this library does not include reactivity. Therefore, it does not provide equivalents to `context.watch`/`context.listen` or `ref.watch`/`ref.listen`. The only way to trigger a rebuild is by changing the key of the `ProviderScope`, which is not recommended by us. Instead, we advise injecting observables/signals directly and using their corresponding widgets or helpers to react to changes.
Users transitioning from Provider or Riverpod should note an important distinction: this library does not include reactivity. Therefore, it does not provide equivalents to `context.watch`/`context.listen` or `ref.watch`/`ref.listen`. The only way to trigger a rebuild is by changing the key of the `ProviderScope`, which is not recommended by us (the next section explains this in detail). Instead, we advise injecting observables/signals directly and using their corresponding widgets or helpers to react to changes.
</Aside>

### Full example
Expand Down
13 changes: 9 additions & 4 deletions docs/src/content/docs/examples/preferences.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Shared prefences example
title: Shared preferences example
description: An example showing how to provide async objects with Disco.
---

Expand All @@ -11,16 +11,20 @@ SharedPreferences is a package that allows you to store key-value pairs on the d
This example shows how to provide a `SharedPreferences` object, after initialization, to the whole app using Disco.
After the initialization, the preferences can be retrieved and updated synchronously.

You can take inspiration to provide other asynchronous objects.

## Dependency

This is the `shared_preferences` version used in this example:
This is the `shared_preferences` version used in the following examples:

```yaml {2}
dependencies:
shared_preferences: ^2.4.0
```

## Code
## Example with error handling

The above below handles the loading and error states of the initialization process correctly and it's the preferred way for handling async initialization in Flutter.

```dart title=main.dart
import 'package:disco/disco.dart';
Expand Down Expand Up @@ -114,9 +118,10 @@ class _MyAppState extends State<MyApp> {
}
```

The above code handles the loading and error states of the initialization process correctly and it's the preferred way for handling async initialization in Flutter.
## Example without error handling

If you know the initialization cannot fail, or it takes just a fraction of a second and you don't want to show the loading state, you can simplify the code as follows:

```dart
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down