Skip to content

Commit 5e6dd74

Browse files
authored
Merge branch 'master' into rekhoff/windows-digicert-binary-signing
2 parents 53bec59 + b150cf6 commit 5e6dd74

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

crates/bindings-typescript/src/react/useTable.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface UseTableCallbacks<RowType> {
2424
onInsert?: (row: RowType) => void;
2525
onDelete?: (row: RowType) => void;
2626
onUpdate?: (oldRow: RowType, newRow: RowType) => void;
27+
/** Whether the subscription is active. Defaults to `true`. */
28+
enabled?: boolean;
2729
}
2830

2931
type MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';
@@ -67,6 +69,7 @@ export function useTable<TableDef extends UntypedTableDef>(
6769
callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>
6870
): [readonly Prettify<RowType<TableDef>>[], boolean] {
6971
type UseTableRowType = RowType<TableDef>;
72+
const enabled = callbacks?.enabled ?? true;
7073
const accessorName = getQueryAccessorName(query);
7174
const whereExpr = getQueryWhereClause(query);
7275

@@ -93,6 +96,9 @@ export function useTable<TableDef extends UntypedTableDef>(
9396
readonly Prettify<UseTableRowType>[],
9497
boolean,
9598
] => {
99+
if (!enabled) {
100+
return [[], true];
101+
}
96102
const connection = connectionState.getConnection();
97103
if (!connection) {
98104
return [[], false];
@@ -107,7 +113,7 @@ export function useTable<TableDef extends UntypedTableDef>(
107113
// TODO: investigating refactoring so that this is no longer necessary, as we have had genuine bugs with missed deps.
108114
// See https://github.com/clockworklabs/SpacetimeDB/pull/4580.
109115
// eslint-disable-next-line react-hooks/exhaustive-deps
110-
}, [connectionState, accessorName, querySql, subscribeApplied]);
116+
}, [connectionState, accessorName, querySql, subscribeApplied, enabled]);
111117

112118
// Invalidate the cached snapshot when computeSnapshot changes (e.g. when
113119
// subscribeApplied flips to true) so getSnapshot() recomputes on the next
@@ -117,6 +123,10 @@ export function useTable<TableDef extends UntypedTableDef>(
117123
}, [computeSnapshot]);
118124

119125
useEffect(() => {
126+
if (!enabled) {
127+
setSubscribeApplied(false);
128+
return;
129+
}
120130
const connection = connectionState.getConnection()!;
121131
if (connectionState.isActive && connection) {
122132
const cancel = connection
@@ -129,10 +139,14 @@ export function useTable<TableDef extends UntypedTableDef>(
129139
cancel.unsubscribe();
130140
};
131141
}
132-
}, [querySql, connectionState.isActive, connectionState]);
142+
}, [querySql, connectionState.isActive, connectionState, enabled]);
133143

134144
const subscribe = useCallback(
135145
(onStoreChange: () => void) => {
146+
if (!enabled) {
147+
return () => {};
148+
}
149+
136150
const onInsert = (
137151
ctx: EventContextInterface<UntypedRemoteModule>,
138152
row: any
@@ -218,6 +232,7 @@ export function useTable<TableDef extends UntypedTableDef>(
218232
callbacks?.onDelete,
219233
callbacks?.onInsert,
220234
callbacks?.onUpdate,
235+
enabled,
221236
]
222237
);
223238

crates/bindings/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,10 @@ impl ReducerContext {
11101110
/// use spacetimedb::{reducer, ReducerContext, Uuid};
11111111
///
11121112
/// #[reducer]
1113-
/// fn generate_uuid_v4(ctx: &ReducerContext) -> Uuid {
1114-
/// let uuid = ctx.new_uuid_v4();
1113+
/// fn generate_uuid_v4(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
1114+
/// let uuid = ctx.new_uuid_v4()?;
11151115
/// log::info!(uuid);
1116+
/// Ok(())
11161117
/// }
11171118
/// # }
11181119
/// ```
@@ -1131,9 +1132,10 @@ impl ReducerContext {
11311132
/// use spacetimedb::{reducer, ReducerContext, Uuid};
11321133
///
11331134
/// #[reducer]
1134-
/// fn generate_uuid_v7(ctx: &ReducerContext) -> Result<Uuid, Box<dyn std::error::Error>> {
1135+
/// fn generate_uuid_v7(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
11351136
/// let uuid = ctx.new_uuid_v7()?;
11361137
/// log::info!(uuid);
1138+
/// Ok(())
11371139
/// }
11381140
/// # }
11391141
/// ```

crates/cli/src/subcommands/login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn cli() -> Command {
2222
.arg(
2323
Arg::new("server")
2424
.long("server-issued-login")
25+
.hide(true)
2526
.group("login-method")
2627
.help("Log in to a SpacetimeDB server directly, without going through a global auth server"),
2728
)

docs/docs/00300-resources/00200-reference/00100-cli-reference/00100-cli-reference.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ Manage your login to the SpacetimeDB CLI
367367
* `--auth-host <AUTH-HOST>` — Fetch login token from a different host
368368

369369
Default value: `https://spacetimedb.com`
370-
* `--server-issued-login <SERVER>` — Log in to a SpacetimeDB server directly, without going through a global auth server
371370
* `--token <SPACETIMEDB-TOKEN>` — Bypass the login flow and use a login token directly
372371
* `--no-browser` — Do not open a browser window
373372

0 commit comments

Comments
 (0)