Skip to content

Commit 58f3c31

Browse files
committed
[release/v1.7.0]: Revert "Remove connection_id from ViewContext (#3464)"
This reverts commit f8631cc.
1 parent 59e566d commit 58f3c31

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/bindings/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ pub struct AnonymousViewContext {
805805
/// Use this type if the view depends on the caller's identity.
806806
pub struct ViewContext {
807807
pub sender: Identity,
808+
pub connection_id: Option<ConnectionId>,
808809
pub db: LocalReadOnly,
809810
}
810811

@@ -941,6 +942,7 @@ impl ReducerContext {
941942
pub fn as_read_only(&self) -> ViewContext {
942943
ViewContext {
943944
sender: self.sender,
945+
connection_id: self.connection_id,
944946
db: LocalReadOnly {},
945947
}
946948
}

crates/bindings/src/rt.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ extern "C" fn __call_view__(
807807
sender_1: u64,
808808
sender_2: u64,
809809
sender_3: u64,
810+
conn_id_0: u64,
811+
conn_id_1: u64,
810812
args: BytesSource,
811813
sink: BytesSink,
812814
) -> i16 {
@@ -815,12 +817,29 @@ extern "C" fn __call_view__(
815817
let sender: [u8; 32] = bytemuck::must_cast(sender);
816818
let sender = Identity::from_byte_array(sender); // The LITTLE-ENDIAN constructor.
817819

820+
// Piece together `conn_id_i` into a `ConnectionId`.
821+
// The all-zeros `ConnectionId` (`ConnectionId::ZERO`) is interpreted as `None`.
822+
let conn_id = [conn_id_0, conn_id_1];
823+
let conn_id: [u8; 16] = bytemuck::must_cast(conn_id);
824+
let conn_id = ConnectionId::from_le_byte_array(conn_id); // The LITTLE-ENDIAN constructor.
825+
let conn_id = (conn_id != ConnectionId::ZERO).then_some(conn_id);
826+
818827
let views = VIEWS.get().unwrap();
819828
let db = LocalReadOnly {};
829+
let connection_id = conn_id;
820830

821831
write_to_sink(
822832
sink,
823-
&with_read_args(args, |args| views[id](ViewContext { sender, db }, args)),
833+
&with_read_args(args, |args| {
834+
views[id](
835+
ViewContext {
836+
sender,
837+
connection_id,
838+
db,
839+
},
840+
args,
841+
)
842+
}),
824843
);
825844
0
826845
}

0 commit comments

Comments
 (0)