mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 20:17:13 +00:00
fix: wasm add client id check
This commit is contained in:
parent
df3a708e48
commit
973486067a
5 changed files with 13 additions and 18 deletions
|
@ -272,10 +272,7 @@ impl Clone for List {
|
|||
}
|
||||
|
||||
impl List {
|
||||
pub(crate) fn from_instance(
|
||||
instance: Arc<Mutex<ContainerInstance>>,
|
||||
client_id: ClientID,
|
||||
) -> Self {
|
||||
pub fn from_instance(instance: Arc<Mutex<ContainerInstance>>, client_id: ClientID) -> Self {
|
||||
Self {
|
||||
instance,
|
||||
client_id,
|
||||
|
|
|
@ -223,10 +223,7 @@ impl Clone for Map {
|
|||
}
|
||||
|
||||
impl Map {
|
||||
pub(crate) fn from_instance(
|
||||
instance: Arc<Mutex<ContainerInstance>>,
|
||||
client_id: ClientID,
|
||||
) -> Self {
|
||||
pub fn from_instance(instance: Arc<Mutex<ContainerInstance>>, client_id: ClientID) -> Self {
|
||||
Self {
|
||||
instance,
|
||||
client_id,
|
||||
|
|
|
@ -291,10 +291,7 @@ impl Clone for Text {
|
|||
}
|
||||
|
||||
impl Text {
|
||||
pub(crate) fn from_instance(
|
||||
instance: Arc<Mutex<ContainerInstance>>,
|
||||
client_id: ClientID,
|
||||
) -> Self {
|
||||
pub fn from_instance(instance: Arc<Mutex<ContainerInstance>>, client_id: ClientID) -> Self {
|
||||
Self {
|
||||
instance,
|
||||
client_id,
|
||||
|
|
|
@ -29,6 +29,10 @@ impl LoroCore {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn client_id(&self) -> ClientID {
|
||||
self.log_store.read().unwrap().this_client_id()
|
||||
}
|
||||
|
||||
pub fn vv(&self) -> VersionVector {
|
||||
self.log_store.read().unwrap().get_vv().clone()
|
||||
}
|
||||
|
|
|
@ -102,21 +102,21 @@ impl LoroMap {
|
|||
pub fn get_text(&mut self, ctx: &mut Loro, key: &str) -> LoroText {
|
||||
let id = self.0.insert_obj(&ctx.0, key, ContainerType::Text);
|
||||
let text = ctx.deref().get_container(&id).unwrap();
|
||||
LoroText(text.into())
|
||||
LoroText(Text::from_instance(text, ctx.deref().client_id()))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getMap")]
|
||||
pub fn get_map(&mut self, ctx: &mut Loro, key: &str) -> LoroMap {
|
||||
let id = self.0.insert_obj(ctx.deref_mut(), key, ContainerType::Map);
|
||||
let map = ctx.deref().get_container(&id).unwrap();
|
||||
LoroMap(map.into())
|
||||
LoroMap(Map::from_instance(map, ctx.deref().client_id()))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getList")]
|
||||
pub fn get_list(&mut self, ctx: &mut Loro, key: &str) -> LoroList {
|
||||
let id = self.0.insert_obj(ctx.deref_mut(), key, ContainerType::List);
|
||||
let list = ctx.deref().get_container(&id).unwrap();
|
||||
LoroList(list.into())
|
||||
LoroList(List::from_instance(list, ctx.deref().client_id()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ impl LoroList {
|
|||
.0
|
||||
.insert_obj(ctx.deref_mut(), index, ContainerType::Text);
|
||||
let text = ctx.deref().get_container(&id).unwrap();
|
||||
LoroText(text.into())
|
||||
LoroText(Text::from_instance(text, ctx.deref().client_id()))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getMap")]
|
||||
|
@ -159,7 +159,7 @@ impl LoroList {
|
|||
.0
|
||||
.insert_obj(ctx.deref_mut(), index, ContainerType::Map);
|
||||
let map = ctx.deref().get_container(&id).unwrap();
|
||||
LoroMap(map.into())
|
||||
LoroMap(Map::from_instance(map, ctx.deref().client_id()))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getList")]
|
||||
|
@ -168,7 +168,7 @@ impl LoroList {
|
|||
.0
|
||||
.insert_obj(ctx.deref_mut(), index, ContainerType::List);
|
||||
let list = ctx.deref().get_container(&id).unwrap();
|
||||
LoroList(list.into())
|
||||
LoroList(List::from_instance(list, ctx.deref().client_id()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue