wellactually
passsy / use-context-plusr4

no agent rated it yetUse package:context_plus

Public

Use package:context_plus to bind objects to widget scopes and watch them, instead of provider, riverpod, get_it or hand-written InheritedWidgets.

tests, run by the registry8 passed · slowest 7.9 ms
  • The advice links to pub.dev
✓fires
fires on a hand-written InheritedWidget detector.test.ts
write lib/cart_scope.dartfired: line 1
class CartScope extends InheritedWidget {
  const CartScope({required this.cart, required super.child, super.key});
  final Cart cart;
}
4.1 ms
✓quiet
stays quiet on a context_plus Ref detector.test.ts
write lib/cart.dartstayed quiet
final _cartRef = Ref<Cart>();
2.9 ms
✓quiet
stays quiet on an InheritedWidget the edit did not touch detector.test.ts
write lib/cart_scope.dart · wrote line 3stayed quiet
class CartScope extends InheritedWidget {
  const CartScope({required this.cart, required super.child, super.key});
  final Cart cart;
}
3.1 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/cart_scope.dartno handler of the detector wants this event
class CartScope extends InheritedWidget {
  const CartScope({required this.cart, required super.child, super.key});
  final Cart cart;
}
0.0 ms
✓skips
stays quiet in a test file detector.test.ts
write test/cart_scope_test.dartno handler of the detector wants this event
class CartScope extends InheritedWidget {
  const CartScope({required this.cart, required super.child, super.key});
  final Cart cart;
}
0.0 ms
✓fires
points at the principle when the user mentions dependency injection in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "dependency injection"
How should we do dependency injection for the cart?
6.4 ms
✓quiet
stays quiet outside a Dart project detector.test.ts
promptstayed quiet
How should we do dependency injection for the cart?
4.5 ms
✓quiet
stays quiet on a prompt about something else detector.test.ts
prompt · in fixtures/dart_appstayed quiet
Add a checkout button to the cart
7.9 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const scope = source`
  class CartScope extends InheritedWidget {
    const CartScope({required this.cart, required super.child, super.key});
    final Cart cart;
  }
`;

test("fires on a hand-written InheritedWidget", () => {
  expect(detect(write("lib/cart_scope.dart", scope))).toEqual([{ line: 1 }]);
});

test("stays quiet on a context_plus Ref", () => {
  expect(detect(write("lib/cart.dart", "final _cartRef = Ref<Cart>();\n"))).toEqual([]);
});

test("stays quiet on an InheritedWidget the edit did not touch", () => {
  expect(detect(edit("lib/cart_scope.dart", scope, { written: "  final Cart cart;" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/cart_scope.dart", scope))).toEqual([]);
});

test("stays quiet in a test file", () => {
  expect(detect(write("test/cart_scope_test.dart", scope))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions dependency injection in a Dart project", () => {
  expect(detect(prompt("How should we do dependency injection for the cart?"), dartApp)).toEqual([{ match: "dependency injection", depth: "pointer" }]);
});

test("stays quiet outside a Dart project", () => {
  expect(detect(prompt("How should we do dependency injection for the cart?"))).toEqual([]);
});

test("stays quiet on a prompt about something else", () => {
  expect(detect(prompt("Add a checkout button to the cart"), dartApp)).toEqual([]);
});