Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacartney committed Jan 2, 2025
1 parent 1ba8293 commit c035a13
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ await counter.add(ctx, "checkboxes", 5); // increment by 5
await counter.inc(ctx, "checkboxes"); // increment by 1
await counter.subtract(ctx, "checkboxes", 5); // decrement by 5
await counter.dec(ctx, "checkboxes"); // decrement by 1
await counter.reset(ctx, "checkboxes"); // reset to 0

const numCheckboxes = counter.for("checkboxes");
await numCheckboxes.inc(ctx); // increment
await numCheckboxes.dec(ctx); // decrement
await numCheckboxes.add(ctx, 5); // add 5
await numCheckboxes.subtract(ctx, 5); // subtract 5
await numCheckboxes.reset(ctx); // reset to 0
```

And you can read the counter's value in a query, mutation, or action.
Expand Down Expand Up @@ -143,7 +145,7 @@ Or by setting a default that applies to all keys not specified in `shards`:
```ts
const counter = new ShardedCounter(components.shardedCounter, {
shards: { checkboxes: 100 },
defaultShards: 20,
defaultShards: 8,
});
```

Expand Down Expand Up @@ -185,7 +187,7 @@ number of shards to form an estimate. You can improve the estimate by reading
from more shards, at the cost of more contention:

```ts
const betterEstimatedCheckboxCount = await counter.estimateCount(ctx, "checkboxes", 3);
const estimateFromThree = await counter.estimateCount(ctx, "checkboxes", 3);
```

If the counter was accumulated from many
Expand Down Expand Up @@ -259,7 +261,7 @@ async function insertUser(ctx, user) {
}
```

3. Register a [Trigger]((https://www.npmjs.com/package/convex-helpers#triggers)),
3. Register a [Trigger](https://www.npmjs.com/package/convex-helpers#triggers),
which automatically runs code when a mutation changes the
data in a table.

Expand Down

0 comments on commit c035a13

Please sign in to comment.