mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
docs(spec): fix README example to use scoped extractors
The previous snippet referenced `state.ax.find` inside an actions() body where state is not in scope, and shadowed the imported actions helper with an export of the same name.
This commit is contained in:
1 parent
25e6725f91
commit
8be26fbf8b
1 file changed
+6
-4
+6
-4
@@ -13,10 +13,12 @@ npm install --save-dev @sanderling/spec
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { extract, always, eventually, now, actions, weighted, taps, swipes, InputText, Tap } from "@sanderling/spec";
|
import { extract, always, eventually, actions, weighted, taps, swipes, InputText, Tap } from "@sanderling/spec";
|
||||||
|
|
||||||
const loggedIn = extract((s) => !!s.ax.find("id:home-tab-bar"));
|
const loggedIn = extract((s) => !!s.ax.find("id:home-tab-bar"));
|
||||||
const balance = extract<number>((s) => (s.snapshots.balance as number) ?? 0);
|
const balance = extract<number>((s) => (s.snapshots.balance as number) ?? 0);
|
||||||
|
const emailField = extract((s) => s.ax.find("id:email-field"));
|
||||||
|
const submitButton = extract((s) => s.ax.find("id:sign-in-button"));
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
balanceNeverNegative: always(() => balance.current >= 0),
|
balanceNeverNegative: always(() => balance.current >= 0),
|
||||||
@@ -25,13 +27,13 @@ export const properties = {
|
|||||||
|
|
||||||
const doLogin = actions(() => {
|
const doLogin = actions(() => {
|
||||||
if (loggedIn.current) return [];
|
if (loggedIn.current) return [];
|
||||||
const email = state.ax.find("id:email-field");
|
const email = emailField.current;
|
||||||
const submit = state.ax.find("id:sign-in-button");
|
const submit = submitButton.current;
|
||||||
if (!email || !submit) return [];
|
if (!email || !submit) return [];
|
||||||
return [InputText({ into: email, text: "[email protected]" }), Tap({ on: submit })];
|
return [InputText({ into: email, text: "[email protected]" }), Tap({ on: submit })];
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actions = weighted(
|
export const actionsRoot = weighted(
|
||||||
[50, doLogin],
|
[50, doLogin],
|
||||||
[10, taps],
|
[10, taps],
|
||||||
[2, swipes],
|
[2, swipes],
|
||||||
|
|||||||
Reference in new issue
Block a user