Skip to content

Commit

Permalink
Renamed examples and fixed comptime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucavenir committed Aug 5, 2023
1 parent c8f43b0 commit 9fba2e2
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 9 deletions.
8 changes: 4 additions & 4 deletions website/docs/migration/1.0.0_to_2.0.0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: ^1.0.0 to ^2.0.0
---

import fromStateNotifier from "./from_state_notifier";
import fromStateNotifier2 from "./from_state_notifier_2";
import buildIinit from "./build_init";
import familyAndDispose from "./family_and_dispose";
import fromStateProvider from "./from_state_provider";
import oldLifecycles from "./old_lifecycles";
import {AutoSnippet} from "../../src/components/CodeSnippet";
Expand Down Expand Up @@ -58,7 +58,7 @@ final diceNotifierProvider = StateNotifierProvider<DiceNotifier, int>((ref) {
```

With the new `Notifier` class, the above example translates to:
<AutoSnippet language="dart" {...fromStateNotifier}></AutoSnippet>
<AutoSnippet language="dart" {...buildIinit}></AutoSnippet>

You can notice the following differences:
- A more concise syntax, with no constructor logic
Expand Down Expand Up @@ -113,7 +113,7 @@ But with `Notifier` (and its `FamilyNotifier` variant), no pipe-down is ever nee
The `.family` modification, which is very important, is clearly stated in its own definition,
and it's used directly in its `build` method.
The whole thing is more readable, more concise and less error-prone.
<AutoSnippet language="dart" {...fromStateNotifier2}></AutoSnippet>
<AutoSnippet language="dart" {...familyAndDispose}></AutoSnippet>

Notice how the code-generated version is even more concise and less error-prone than ever.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'notifier.g.dart';
import '../utils.dart';

part 'build_init.g.dart';

Future<void> _startCamera() async {}

/* SNIPPET START */
@riverpod
Expand Down
27 changes: 27 additions & 0 deletions website/docs/migration/build_init/build_init.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import raw from "!!raw-loader!./raw.dart";
import codegen from "!!raw-loader!./from_state_notifier.dart";
import codegen from "!!raw-loader!./build_init.dart";

export default {
raw,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../utils.dart';

Future<void> _startCamera() async {}

/* SNIPPET START */
class DiceNotifier extends Notifier<int> {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'notifier.g.dart';
import '../utils.dart';

part 'family_and_dispose.g.dart';

/* SNIPPET START */
@riverpod
Expand Down
128 changes: 128 additions & 0 deletions website/docs/migration/family_and_dispose/family_and_dispose.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import raw from "!!raw-loader!./raw.dart";
import codegen from "!!raw-loader!./from_state_notifier_2.dart";
import codegen from "!!raw-loader!./family_and_dispose.dart";

export default {
raw,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../utils.dart';

/* SNIPPET START */
class DiceNotifier extends FamilyNotifier<int, String> {
late String _id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'notifier.g.dart';
part 'from_state_provider.g.dart';

/* SNIPPET START */
@riverpod
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/docs/migration/old_lifecycles/old_lifecycles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:async';

import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../utils.dart';

part 'old_lifecycles.g.dart';

/* SNIPPET START */
Expand Down
27 changes: 27 additions & 0 deletions website/docs/migration/old_lifecycles/old_lifecycles.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/docs/migration/old_lifecycles/raw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:async';

import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../utils.dart';

/* SNIPPET START */
class MyNotifier extends Notifier<int> {
late Timer _timer;
Expand Down
19 changes: 19 additions & 0 deletions website/docs/migration/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:math' as math;

import 'package:hooks_riverpod/hooks_riverpod.dart';

final randomProvider = Provider<int>((ref) {
return math.Random().nextInt(6);
});

final myRepositoryProvider = Provider<SomeRepo>((ref) {
return SomeRepo();
});

class SomeRepo {
Future<void> post({required String id, required int change}) async {}
}

final durationProvider = Provider<Duration>((ref) {
return Duration.zero;
});

0 comments on commit 9fba2e2

Please sign in to comment.