Skip to content

Commit af93785

Browse files
authored
docs(examples): add todos example (#236)
1 parent 1fcb2ac commit af93785

30 files changed

+1096
-0
lines changed

.github/workflows/examples_todos.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: examples/todos
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
pull_request:
9+
paths:
10+
- "examples/todos/routes/**"
11+
- "examples/todos/lib/**"
12+
- "examples/todos/test/**"
13+
- "examples/todos/packages/**/lib/**"
14+
- "examples/todos/packages/**/test/**"
15+
- ".github/workflows/examples_todos.yaml"
16+
branches:
17+
- main
18+
19+
jobs:
20+
build:
21+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
22+
with:
23+
working_directory: examples/todos
24+
analyze_directories: "routes test"
25+
report_on: "routes"
26+
27+
todos_data_source:
28+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
29+
with:
30+
working_directory: examples/todos/packages/todos_data_source
31+
32+
in_memory_todos_data_source:
33+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
34+
with:
35+
working_directory: examples/todos/packages/in_memory_todos_data_source

examples/todos/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See https://www.dartlang.org/guides/libraries/private-files
2+
3+
# Files and directories created by pub
4+
.dart_tool/
5+
.packages
6+
pubspec.lock
7+
8+
# Files and directories created by dart_frog
9+
build/
10+
.dart_frog
11+
12+
# Test related files
13+
coverage/

examples/todos/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# todos
2+
3+
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
4+
[![License: MIT][license_badge]][license_link]
5+
6+
An example todos app built with `dart_frog`.
7+
8+
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
9+
[license_link]: https://opensource.org/licenses/MIT
10+
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
11+
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis

examples/todos/analysis_options.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include: package:very_good_analysis/analysis_options.3.0.1.yaml
2+
analyzer:
3+
exclude:
4+
- build/**
5+
linter:
6+
rules:
7+
file_names: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# See https://www.dartlang.org/guides/libraries/private-files
2+
3+
# Files and directories created by pub
4+
.dart_tool/
5+
.packages
6+
build/
7+
pubspec.lock
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# In Memory Todos Data Source
2+
3+
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
4+
[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)
5+
[![License: MIT][license_badge]][license_link]
6+
7+
An in-memory implementation of the TodosDataSource interface.
8+
9+
## Installation 💻
10+
11+
**❗ In order to start using In Memory Todos Data Source you must have the [Dart SDK][dart_install_link] installed on your machine.**
12+
13+
Add `in_memory_todos_data_source` to your `pubspec.yaml`:
14+
15+
```yaml
16+
dependencies:
17+
in_memory_todos_data_source:
18+
```
19+
20+
Install it:
21+
22+
```sh
23+
dart pub get
24+
```
25+
26+
---
27+
28+
## Continuous Integration 🤖
29+
30+
In Memory Todos Data Source comes with a built-in [GitHub Actions workflow][github_actions_link] powered by [Very Good Workflows][very_good_workflows_link] but you can also add your preferred CI/CD solution.
31+
32+
Out of the box, on each pull request and push, the CI `formats`, `lints`, and `tests` the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses [Very Good Analysis][very_good_analysis_link] for a strict set of analysis options used by our team. Code coverage is enforced using the [Very Good Workflows][very_good_coverage_link].
33+
34+
---
35+
36+
## Running Tests 🧪
37+
38+
To run all unit tests:
39+
40+
```sh
41+
dart pub global activate coverage 1.2.0
42+
dart test --coverage=coverage
43+
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
44+
```
45+
46+
To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov).
47+
48+
```sh
49+
# Generate Coverage Report
50+
genhtml coverage/lcov.info -o coverage/
51+
52+
# Open Coverage Report
53+
open coverage/index.html
54+
```
55+
56+
[dart_install_link]: https://dart.dev/get-dart
57+
[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions
58+
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
59+
[license_link]: https://opensource.org/licenses/MIT
60+
[logo_black]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_black.png#gh-light-mode-only
61+
[logo_white]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_white.png#gh-dark-mode-only
62+
[mason_link]: https://github.com/felangel/mason
63+
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
64+
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
65+
[very_good_coverage_link]: https://github.com/marketplace/actions/very-good-coverage
66+
[very_good_ventures_link]: https://verygood.ventures
67+
[very_good_ventures_link_light]: https://verygood.ventures#gh-light-mode-only
68+
[very_good_ventures_link_dark]: https://verygood.ventures#gh-dark-mode-only
69+
[very_good_workflows_link]: https://github.com/VeryGoodOpenSource/very_good_workflows
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:very_good_analysis/analysis_options.3.0.1.yaml
Lines changed: 20 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// An in-memory implementation of the TodosDataSource interface.
2+
library in_memory_todos_data_source;
3+
4+
export 'package:todos_data_source/todos_data_source.dart';
5+
6+
export 'src/in_memory_todos_data_source.dart';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:todos_data_source/todos_data_source.dart';
2+
import 'package:uuid/uuid.dart';
3+
4+
/// An in-memory implementation of the [TodosDataSource] interface.
5+
class InMemoryTodosDataSource implements TodosDataSource {
6+
/// Map of ID -> Todo
7+
final _cache = <String, Todo>{};
8+
9+
@override
10+
Future<Todo> create(Todo todo) async {
11+
final id = const Uuid().v4();
12+
final createdTodo = todo.copyWith(id: id);
13+
_cache[id] = createdTodo;
14+
return createdTodo;
15+
}
16+
17+
@override
18+
Future<List<Todo>> readAll() async => _cache.values.toList();
19+
20+
@override
21+
Future<Todo?> read(String id) async => _cache[id];
22+
23+
@override
24+
Future<Todo> update(String id, Todo todo) async {
25+
return _cache.update(id, (value) => todo);
26+
}
27+
28+
@override
29+
Future<void> delete(String id) async => _cache.remove(id);
30+
}

0 commit comments

Comments
 (0)