Skip to content

Commit

Permalink
docs: update terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryConrad committed Jul 23, 2023
1 parent 2b699f0 commit f66a6a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Specifically, rearch is a:
- 🧱 Composable
- 🔌 Extendable
- ⬆️ Scalable
- 🧮 Functional
- 🪢 Databinding
- 💉 Dependency Injection

Expand Down Expand Up @@ -203,10 +204,10 @@ to accomodate one-off situations, all in addition to a barrage of types to suppo
`AutoDispose...`, [etc.](https://pub.dev/documentation/riverpod/latest/riverpod/riverpod-library.html)).

Instead of AutoDispose, rearch:
- Introduces the novel concept of _super pure_ capsules when dealing with global state.
- You don't need to know anything about super pure capsules when using rearch;
- Introduces the novel concept of _idempotent_ capsules when dealing with global state.
- You don't need to know anything about idempotent capsules when using rearch;
they are identified internally and are automatically cleaned up for you!
- Embraces the use factories and side effects for ephemeral state.
- Embraces the use of factories and side effects for ephemeral state.

### Why not Hooks?
I actually love `flutter_hooks`! Just a few grievances:
Expand Down
8 changes: 4 additions & 4 deletions packages/rearch/lib/rearch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class CapsuleContainer implements Disposable {
/// and then after any capsules its listening to change.
@UseResult('ListenerHandle will leak its listener if it is not disposed')
ListenerHandle listen(CapsuleListener listener) {
// Create a temporary *impure* capsule so that it doesn't get super-pure
// garbage collected
// Create a temporary *non-idempotent* capsule so that it doesn't get
// idempotent garbage collected
void capsule(CapsuleHandle use) {
use.register((_) {});
listener(use);
Expand All @@ -109,9 +109,9 @@ class CapsuleContainer implements Disposable {
Capsule<T> capsule,
void Function() callback,
) {
// This uses the fact that if we add a super pure capsule, it will be
// This uses the fact that if we add an idempotent capsule, it will be
// automatically disposed whenever the supplied capsule is updated/disposed
// via the super pure gc.
// via the idempotent gc.
void tempCapsule(CapsuleHandle use) => use<T>(capsule);
final manager = _CapsuleManager(this, tempCapsule);
manager.toDispose.add(callback);
Expand Down
44 changes: 22 additions & 22 deletions packages/rearch/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ void main() {
return use.state(0);
}

int unchangingSuperPureDep(CapsuleHandle use) {
int unchangingIdempotentDep(CapsuleHandle use) {
builds.update(
unchangingSuperPureDep,
unchangingIdempotentDep,
(count) => count + 1,
ifAbsent: () => 1,
);
Expand All @@ -165,12 +165,12 @@ void main() {
(count) => count + 1,
ifAbsent: () => 1,
);
return use(unchangingSuperPureDep);
return use(unchangingIdempotentDep);
}

int changingSuperPureDep(CapsuleHandle use) {
int changingIdempotentDep(CapsuleHandle use) {
builds.update(
changingSuperPureDep,
changingIdempotentDep,
(count) => count + 1,
ifAbsent: () => 1,
);
Expand All @@ -183,7 +183,7 @@ void main() {
(count) => count + 1,
ifAbsent: () => 1,
);
return use(changingSuperPureDep);
return use(changingIdempotentDep);
}

void impureSink(CapsuleHandle use) {
Expand All @@ -197,56 +197,56 @@ void main() {
expect(container.read(unchangingWatcher), equals(0));
expect(container.read(changingWatcher), equals(0));
expect(builds[stateful], equals(1));
expect(builds[unchangingSuperPureDep], equals(1));
expect(builds[changingSuperPureDep], equals(1));
expect(builds[unchangingIdempotentDep], equals(1));
expect(builds[changingIdempotentDep], equals(1));
expect(builds[unchangingWatcher], equals(1));
expect(builds[changingWatcher], equals(1));

container.read(stateful).$2(0);
expect(builds[stateful], equals(1));
expect(builds[unchangingSuperPureDep], equals(1));
expect(builds[changingSuperPureDep], equals(1));
expect(builds[unchangingIdempotentDep], equals(1));
expect(builds[changingIdempotentDep], equals(1));
expect(builds[unchangingWatcher], equals(1));
expect(builds[changingWatcher], equals(1));

expect(container.read(unchangingWatcher), equals(0));
expect(container.read(changingWatcher), equals(0));
expect(builds[stateful], equals(1));
expect(builds[unchangingSuperPureDep], equals(1));
expect(builds[changingSuperPureDep], equals(1));
expect(builds[unchangingIdempotentDep], equals(1));
expect(builds[changingIdempotentDep], equals(1));
expect(builds[unchangingWatcher], equals(1));
expect(builds[changingWatcher], equals(1));

container.read(stateful).$2(1);
expect(builds[stateful], equals(2));
expect(builds[unchangingSuperPureDep], equals(1));
expect(builds[changingSuperPureDep], equals(1));
expect(builds[unchangingIdempotentDep], equals(1));
expect(builds[changingIdempotentDep], equals(1));
expect(builds[unchangingWatcher], equals(1));
expect(builds[changingWatcher], equals(1));

expect(container.read(unchangingWatcher), equals(0));
expect(container.read(changingWatcher), equals(1));
expect(builds[stateful], equals(2));
expect(builds[unchangingSuperPureDep], equals(2));
expect(builds[changingSuperPureDep], equals(2));
expect(builds[unchangingIdempotentDep], equals(2));
expect(builds[changingIdempotentDep], equals(2));
expect(builds[unchangingWatcher], equals(2));
expect(builds[changingWatcher], equals(2));

// Disable the super pure gc
// Disable the idempotent gc
container.read(impureSink);

container.read(stateful).$2(2);
expect(builds[stateful], equals(3));
expect(builds[unchangingSuperPureDep], equals(3));
expect(builds[changingSuperPureDep], equals(3));
expect(builds[unchangingIdempotentDep], equals(3));
expect(builds[changingIdempotentDep], equals(3));
expect(builds[unchangingWatcher], equals(2));
expect(builds[changingWatcher], equals(3));

expect(container.read(unchangingWatcher), equals(0));
expect(container.read(changingWatcher), equals(2));
expect(builds[stateful], equals(3));
expect(builds[unchangingSuperPureDep], equals(3));
expect(builds[changingSuperPureDep], equals(3));
expect(builds[unchangingIdempotentDep], equals(3));
expect(builds[changingIdempotentDep], equals(3));
expect(builds[unchangingWatcher], equals(2));
expect(builds[changingWatcher], equals(3));
});
Expand All @@ -258,7 +258,7 @@ void main() {
// \ / \
// H -> E -> F -> G
//
// C, D, E, G, H are super pure. A, B, F are not.
// C, D, E, G, H are idempotent. A, B, F are not.
test('complex dependency graph', () {
final builds = <Capsule<Object?>, int>{};

Expand Down

0 comments on commit f66a6a9

Please sign in to comment.