Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: add select to atom (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay authored Aug 9, 2022
1 parent 52ea7d1 commit 3fcd111
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion effect/sys/Atom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { E_, Effect, Resolved, T_, ValCollection } from "./Effect.ts";
import { select } from "../atoms/Select.ts";
import { E_, Effect, Resolved, T_, Val, ValCollection } from "./Effect.ts";
import { key } from "./key.ts";
import { run, RunContext, RunResult } from "./run.ts";

Expand All @@ -23,6 +24,10 @@ export class Atom<N extends string, A extends unknown[], R>
super(fqn);
}

select(field: Val<keyof T_<this>>) {
return select(this, field);
}

run(): RunResult<this> {
return run(this);
}
Expand Down
8 changes: 5 additions & 3 deletions examples/those_of_subxt/read_era_rewards.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as C from "../../mod.ts";
import * as U from "../../util/mod.ts";

const activeEra = C.readEntry(C.polkadot, "Staking", "ActiveEra", []);
const activeEraIndex = C.select(C.select(activeEra, "value"), "index");
const eraRewardPoints = C.readEntry(C.polkadot, "Staking", "ErasRewardPoints", [activeEraIndex]);
const idx = C
.readEntry(C.polkadot, "Staking", "ActiveEra", [])
.select("value")
.select("index");
const eraRewardPoints = C.readEntry(C.polkadot, "Staking", "ErasRewardPoints", [idx]);

console.log(U.throwIfError(await eraRewardPoints.run()));

0 comments on commit 3fcd111

Please sign in to comment.