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

Update lite_ref version and flutter dependency constraint #12

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions packages/lite_ref/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.6.0

- Update flutter dependency constraint

## 0.5.2

- [Refactor] Add core package as a dependency.

## 0.5.1

- [Fix] Remove `dispose` function when overriding with `autoDispose` set to `false`.
Expand Down
9 changes: 7 additions & 2 deletions packages/lite_ref/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: lite_ref
description: A lightweight dependency injection package with support for overriding for testing.
version: 0.5.1
version: 0.6.0
repository: https://github.com/jinyus/lite_ref

environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0"
flutter: ">=3.17.0-1.0.pre.38"

dependencies:
basic_interfaces: ^1.0.4
Expand All @@ -17,3 +17,8 @@ dev_dependencies:
flutter_test:
sdk: flutter
very_good_analysis: ^5.1.0

topics:
- dependency-injection
- provider
- di
4 changes: 4 additions & 0 deletions packages/lite_ref_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1

- Update readme

## 0.1.0

- Initial release
108 changes: 64 additions & 44 deletions packages/lite_ref_core/README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,82 @@
# Lite Ref Core
<p align="center">
<img width="500" src="https://github.com/jinyus/lite_ref/blob/main/assets/lite_ref_banner.jpg?raw=true">
</p>

[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)
[![License: MIT][license_badge]][license_link]
<p align="center">
<img src="https://img.shields.io/badge/license-MIT-purple">
<a href="https://app.codecov.io/github/jinyus/lite_ref"><img src="https://img.shields.io/codecov/c/github/jinyus/lite_ref"></a>
<a href="https://pub.dev/packages/lite_ref"><img src="https://img.shields.io/pub/points/lite_ref?color=blue"></a>
</p>

A Very Good Project created by Very Good CLI.
## Overview

## Installation 💻
Lite Ref is a lightweight dependency injection library for Dart and Flutter.

**❗ In order to start using Lite Ref Core you must have the [Dart SDK][dart_install_link] installed on your machine.**
## Installation

Install via `dart pub add`:

```sh
dart pub add lite_ref_core
```bash
dart pub add lite_ref
```

---
## Why Lite Ref?

## Continuous Integration 🤖
- **Fast**: Doesn't use hashmaps to store instances so it's faster than _all_ other DI libraries.
- **Safe**: Uses top level variables so it's impossible to get a NOT_FOUND error.
- **Lightweight**: Has no dependencies.
- **Simple**: Easy to learn with a small API surface:

Lite Ref Core 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.
- Create a singleton:

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].
```dart
final dbRef = Ref.singleton(() => Database());

---
assert(dbRef.instance == dbRef.instance);
```

## Running Tests 🧪
- Use it:

To run all unit tests:
```dart
final db = dbRef.instance; // or dbRef()
```

```sh
dart pub global activate coverage 1.2.0
dart test --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
```
- Override it (for testing):

To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov).
```dart
dbRef.overrideWith(() => MockDatabase());
```

```sh
# Generate Coverage Report
genhtml coverage/lcov.info -o coverage/
- Freeze it (disable overriding):

# Open Coverage Report
open coverage/index.html
```
```dart
// overrideWith is marked as @visibleForTesting so this isn't really necessary.
dbRef.freeze();
```

- Create a transient instance (always return new instance):

```dart
final dbRef = Ref.transient(() => Database());

assert(dbRef.instance != dbRef.instance);
```

- Create a singleton asynchronously:

```dart
final dbRef = Ref.asyncSingleton(() async => await Database.init());
```

- Use it:

```dart
final db = await dbRef.instance;
```

- Use it synchronously:

```dart
// only use this if you know the instance is already created
final db = dbRef.assertInstance;
```

[dart_install_link]: https://dart.dev/get-dart
[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[logo_black]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_black.png#gh-light-mode-only
[logo_white]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_white.png#gh-dark-mode-only
[mason_link]: https://github.com/felangel/mason
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
[very_good_coverage_link]: https://github.com/marketplace/actions/very-good-coverage
[very_good_ventures_link]: https://verygood.ventures
[very_good_ventures_link_light]: https://verygood.ventures#gh-light-mode-only
[very_good_ventures_link_dark]: https://verygood.ventures#gh-dark-mode-only
[very_good_workflows_link]: https://github.com/VeryGoodOpenSource/very_good_workflows
### Click [here](https://github.com/jinyus/lite_ref/tree/main/example/flutter_example) for a flutter example with testing.
7 changes: 6 additions & 1 deletion packages/lite_ref_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: lite_ref_core
description: A lightweight dependency injection package for dart and flutter with support for overriding for testing.
version: 0.1.0
version: 0.1.1
repository: https://github.com/jinyus/lite_ref

environment:
Expand All @@ -12,3 +12,8 @@ dependencies:
dev_dependencies:
test: ^1.25.2
very_good_analysis: ^5.1.0

topics:
- dependency-injection
- provider
- di