mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 05:24:51 +00:00
Merge pull request #12 from loro-dev/refactor-remove-parallel-feat
Refactor: remove isomophic and parallel feature in loro-core
This commit is contained in:
commit
3ec8f4ce00
23 changed files with 1579 additions and 132 deletions
|
@ -48,7 +48,6 @@ doctest = false
|
|||
|
||||
[features]
|
||||
wasm = ["wasm-bindgen", "js-sys"]
|
||||
parallel = []
|
||||
mem-prof = []
|
||||
# whether to use list slice instead of raw str in text container
|
||||
fuzzing = ["crdt-list/fuzzing", "rand", "arbitrary", "tabled"]
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
sync::{RwLockReadGuard, RwLockWriteGuard},
|
||||
};
|
||||
|
||||
use enum_as_inner::EnumAsInner;
|
||||
use fxhash::FxHashMap;
|
||||
use owning_ref::{OwningRef, OwningRefMut};
|
||||
|
||||
use crate::{
|
||||
isomorph::{IsoRef, IsoRefMut},
|
||||
log_store::LogStoreWeakRef,
|
||||
op::RemoteOp,
|
||||
span::IdSpan,
|
||||
LogStore, LoroError,
|
||||
};
|
||||
use crate::{log_store::LogStoreWeakRef, op::RemoteOp, span::IdSpan, LogStore, LoroError};
|
||||
|
||||
use super::{
|
||||
map::MapContainer, text::text_container::TextContainer, Container, ContainerID, ContainerType,
|
||||
|
@ -153,21 +150,23 @@ impl ContainerManager {
|
|||
}
|
||||
|
||||
pub struct ContainerRefMut<'a, T> {
|
||||
value: OwningRefMut<IsoRefMut<'a, ContainerManager>, Box<T>>,
|
||||
value: OwningRefMut<RwLockWriteGuard<'a, ContainerManager>, Box<T>>,
|
||||
}
|
||||
|
||||
pub struct ContainerRef<'a, T> {
|
||||
value: OwningRef<IsoRef<'a, ContainerManager>, Box<T>>,
|
||||
value: OwningRef<RwLockReadGuard<'a, ContainerManager>, Box<T>>,
|
||||
}
|
||||
|
||||
impl<'a, T> From<OwningRefMut<IsoRefMut<'a, ContainerManager>, Box<T>>> for ContainerRefMut<'a, T> {
|
||||
fn from(value: OwningRefMut<IsoRefMut<'a, ContainerManager>, Box<T>>) -> Self {
|
||||
impl<'a, T> From<OwningRefMut<RwLockWriteGuard<'a, ContainerManager>, Box<T>>>
|
||||
for ContainerRefMut<'a, T>
|
||||
{
|
||||
fn from(value: OwningRefMut<RwLockWriteGuard<'a, ContainerManager>, Box<T>>) -> Self {
|
||||
ContainerRefMut { value }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> From<OwningRef<IsoRef<'a, ContainerManager>, Box<T>>> for ContainerRef<'a, T> {
|
||||
fn from(value: OwningRef<IsoRef<'a, ContainerManager>, Box<T>>) -> Self {
|
||||
impl<'a, T> From<OwningRef<RwLockReadGuard<'a, ContainerManager>, Box<T>>> for ContainerRef<'a, T> {
|
||||
fn from(value: OwningRef<RwLockReadGuard<'a, ContainerManager>, Box<T>>) -> Self {
|
||||
ContainerRef { value }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ impl MapContainer {
|
|||
pub fn insert(&mut self, key: InternalString, value: InsertValue) {
|
||||
let self_id = &self.id;
|
||||
let m = self.store.upgrade().unwrap();
|
||||
let mut store = m.write();
|
||||
let mut store = m.write().unwrap();
|
||||
let client_id = store.this_client_id;
|
||||
let order = TotalOrderStamp {
|
||||
client_id,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#![cfg(test)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use fxhash::FxHashMap;
|
||||
use proptest::prelude::*;
|
||||
use proptest::proptest;
|
||||
|
||||
use crate::isomorph::Irc;
|
||||
use crate::value::proptest::gen_insert_value;
|
||||
use crate::Container;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use crate::{fx_map, value::InsertValue, LoroCore, LoroValue};
|
|||
#[test]
|
||||
fn basic() {
|
||||
let mut loro = LoroCore::default();
|
||||
let _weak = Irc::downgrade(&loro.log_store);
|
||||
let _weak = Arc::downgrade(&loro.log_store);
|
||||
let mut container = loro.get_or_create_root_map("map").unwrap();
|
||||
container.insert("haha".into(), InsertValue::Int32(1));
|
||||
let ans = fx_map!(
|
||||
|
@ -37,7 +37,7 @@ mod map_proptest {
|
|||
value in prop::collection::vec(gen_insert_value(), 0..10 * PROPTEST_FACTOR_10)
|
||||
) {
|
||||
let mut loro = LoroCore::default();
|
||||
let _weak = Irc::downgrade(&loro.log_store);
|
||||
let _weak = Arc::downgrade(&loro.log_store);
|
||||
let mut container = loro.get_or_create_root_map("map").unwrap();
|
||||
let mut map: HashMap<String, InsertValue> = HashMap::new();
|
||||
for (k, v) in key.iter().zip(value.iter()) {
|
||||
|
|
|
@ -62,7 +62,7 @@ impl TextContainer {
|
|||
}
|
||||
|
||||
let s = self.log_store.upgrade().unwrap();
|
||||
let mut store = s.write();
|
||||
let mut store = s.write().unwrap();
|
||||
let id = store.next_id();
|
||||
let slice = self.raw_str.alloc(text);
|
||||
self.state.insert(pos, slice.clone());
|
||||
|
@ -93,7 +93,7 @@ impl TextContainer {
|
|||
}
|
||||
|
||||
let s = self.log_store.upgrade().unwrap();
|
||||
let mut store = s.write();
|
||||
let mut store = s.write().unwrap();
|
||||
let id = store.next_id();
|
||||
let op = Op::new(
|
||||
id,
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
#![allow(unused)]
|
||||
use std::{
|
||||
cell::{Ref, RefCell, RefMut},
|
||||
rc::{Rc, Weak as RcWeak},
|
||||
sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard, Weak as ArcWeak},
|
||||
};
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub(crate) type Irc<T> = Arc<T>;
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
pub(crate) type Irc<T> = Rc<T>;
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub(crate) type IsoWeak<T> = ArcWeak<T>;
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
pub(crate) type IsoWeak<T> = RcWeak<T>;
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct IsoRw<T>(RwLock<T>);
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct IsoRw<T>(RefCell<T>);
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub(crate) type IsoRef<'a, T> = RwLockReadGuard<'a, T>;
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
pub(crate) type IsoRef<'a, T> = Ref<'a, T>;
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub(crate) type IsoRefMut<'a, T> = RwLockWriteGuard<'a, T>;
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
pub(crate) type IsoRefMut<'a, T> = RefMut<'a, T>;
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
mod rw_parallel {
|
||||
use super::*;
|
||||
|
||||
impl<T> IsoRw<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(t: T) -> Self {
|
||||
Self(RwLock::new(t))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn read(&self) -> std::sync::RwLockReadGuard<T> {
|
||||
self.0.read().unwrap()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn write(&self) -> std::sync::RwLockWriteGuard<T> {
|
||||
self.0.write().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "parallel"))]
|
||||
mod rw_single {
|
||||
use std::{cell::RefCell, ops::Deref};
|
||||
|
||||
use super::IsoRw;
|
||||
|
||||
impl<T> IsoRw<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(t: T) -> Self {
|
||||
IsoRw(RefCell::new(t))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn read(&self) -> std::cell::Ref<T> {
|
||||
self.0.borrow()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn write(&self) -> std::cell::RefMut<T> {
|
||||
self.0.borrow_mut()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ pub mod version;
|
|||
mod error;
|
||||
#[cfg(feature = "fuzzing")]
|
||||
pub mod fuzz;
|
||||
mod isomorph;
|
||||
mod loro;
|
||||
mod smstring;
|
||||
mod snapshot;
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
//!
|
||||
//!
|
||||
mod iter;
|
||||
use std::{marker::PhantomPinned, ops::Range};
|
||||
use std::{
|
||||
marker::PhantomPinned,
|
||||
ops::Range,
|
||||
sync::{Arc, RwLock, Weak},
|
||||
};
|
||||
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
|
||||
|
@ -20,7 +24,6 @@ use crate::{
|
|||
dag::Dag,
|
||||
debug_log,
|
||||
id::{ClientID, ContainerIdx, Counter},
|
||||
isomorph::{Irc, IsoRw, IsoWeak},
|
||||
op::RemoteOp,
|
||||
span::{HasCounterSpan, HasIdSpan, HasLamportSpan, IdSpan},
|
||||
Lamport, Op, Timestamp, VersionVector, ID,
|
||||
|
@ -44,8 +47,8 @@ impl Default for GcConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) type LogStoreRef = Irc<IsoRw<LogStore>>;
|
||||
pub(crate) type LogStoreWeakRef = IsoWeak<IsoRw<LogStore>>;
|
||||
pub(crate) type LogStoreRef = Arc<RwLock<LogStore>>;
|
||||
pub(crate) type LogStoreWeakRef = Weak<RwLock<LogStore>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// LogStore stores the full history of Loro
|
||||
|
@ -64,8 +67,8 @@ pub struct LogStore {
|
|||
pub(crate) this_client_id: ClientID,
|
||||
frontier: SmallVec<[ID; 2]>,
|
||||
/// CRDT container manager
|
||||
pub(crate) container: IsoWeak<IsoRw<ContainerManager>>,
|
||||
to_self: IsoWeak<IsoRw<LogStore>>,
|
||||
pub(crate) container: Weak<RwLock<ContainerManager>>,
|
||||
to_self: Weak<RwLock<LogStore>>,
|
||||
container_to_idx: FxHashMap<ContainerID, u32>,
|
||||
idx_to_container: Vec<ContainerID>,
|
||||
_pin: PhantomPinned,
|
||||
|
@ -75,11 +78,11 @@ impl LogStore {
|
|||
pub(crate) fn new(
|
||||
mut cfg: Configure,
|
||||
client_id: Option<ClientID>,
|
||||
container: IsoWeak<IsoRw<ContainerManager>>,
|
||||
) -> Irc<IsoRw<Self>> {
|
||||
container: Weak<RwLock<ContainerManager>>,
|
||||
) -> Arc<RwLock<Self>> {
|
||||
let this_client_id = client_id.unwrap_or_else(|| cfg.rand.next_u64());
|
||||
Irc::new_cyclic(|x| {
|
||||
IsoRw::new(Self {
|
||||
Arc::new_cyclic(|x| {
|
||||
RwLock::new(Self {
|
||||
cfg,
|
||||
this_client_id,
|
||||
changes: FxHashMap::default(),
|
||||
|
@ -175,7 +178,7 @@ impl LogStore {
|
|||
|
||||
fn change_to_export_format(&self, change: Change) -> Change<RemoteOp> {
|
||||
let upgraded = self.container.upgrade().unwrap();
|
||||
let container_manager = upgraded.read();
|
||||
let container_manager = upgraded.read().unwrap();
|
||||
let mut ops = RleVec::new();
|
||||
for mut op in change.ops.into_iter() {
|
||||
let container = container_manager
|
||||
|
@ -296,7 +299,7 @@ impl LogStore {
|
|||
|
||||
// TODO: find a way to remove this clone? we don't need change in apply method actually
|
||||
let upgraded = self.container.upgrade().unwrap();
|
||||
let mut container_manager = upgraded.write();
|
||||
let mut container_manager = upgraded.write().unwrap();
|
||||
let change = self.change_to_imported_format(&mut container_manager, change);
|
||||
let v = self
|
||||
.changes
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use owning_ref::{OwningRef, OwningRefMut};
|
||||
|
||||
use crate::{
|
||||
|
@ -10,14 +12,13 @@ use crate::{
|
|||
ContainerID, ContainerType,
|
||||
},
|
||||
id::ClientID,
|
||||
isomorph::{Irc, IsoRw},
|
||||
op::RemoteOp,
|
||||
LogStore, LoroError, VersionVector,
|
||||
};
|
||||
|
||||
pub struct LoroCore {
|
||||
pub(crate) log_store: Irc<IsoRw<LogStore>>,
|
||||
pub(crate) container: Irc<IsoRw<ContainerManager>>,
|
||||
pub(crate) log_store: Arc<RwLock<LogStore>>,
|
||||
pub(crate) container: Arc<RwLock<ContainerManager>>,
|
||||
}
|
||||
|
||||
impl Default for LoroCore {
|
||||
|
@ -28,8 +29,8 @@ impl Default for LoroCore {
|
|||
|
||||
impl LoroCore {
|
||||
pub fn new(cfg: Configure, client_id: Option<ClientID>) -> Self {
|
||||
let container = Irc::new(IsoRw::new(ContainerManager::new()));
|
||||
let weak = Irc::downgrade(&container);
|
||||
let container = Arc::new(RwLock::new(ContainerManager::new()));
|
||||
let weak = Arc::downgrade(&container);
|
||||
Self {
|
||||
log_store: LogStore::new(cfg, client_id, weak),
|
||||
container,
|
||||
|
@ -37,7 +38,7 @@ impl LoroCore {
|
|||
}
|
||||
|
||||
pub fn vv(&self) -> VersionVector {
|
||||
self.log_store.read().get_vv().clone()
|
||||
self.log_store.read().unwrap().get_vv().clone()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -45,10 +46,13 @@ impl LoroCore {
|
|||
&mut self,
|
||||
name: &str,
|
||||
) -> Result<ContainerRefMut<MapContainer>, LoroError> {
|
||||
let mut a = OwningRefMut::new(self.container.write());
|
||||
let mut a = OwningRefMut::new(self.container.write().unwrap());
|
||||
let id = ContainerID::new_root(name, ContainerType::Map);
|
||||
self.log_store.write().get_or_create_container_idx(&id);
|
||||
let ptr = Irc::downgrade(&self.log_store);
|
||||
self.log_store
|
||||
.write()
|
||||
.unwrap()
|
||||
.get_or_create_container_idx(&id);
|
||||
let ptr = Arc::downgrade(&self.log_store);
|
||||
a.get_or_create(&id, ptr)?;
|
||||
Ok(
|
||||
a.map_mut(move |x| x.get_mut(&id).unwrap().as_map_mut().unwrap())
|
||||
|
@ -61,10 +65,13 @@ impl LoroCore {
|
|||
&mut self,
|
||||
name: &str,
|
||||
) -> Result<ContainerRefMut<TextContainer>, LoroError> {
|
||||
let mut a = OwningRefMut::new(self.container.write());
|
||||
let mut a = OwningRefMut::new(self.container.write().unwrap());
|
||||
let id = ContainerID::new_root(name, ContainerType::Text);
|
||||
self.log_store.write().get_or_create_container_idx(&id);
|
||||
let ptr = Irc::downgrade(&self.log_store);
|
||||
self.log_store
|
||||
.write()
|
||||
.unwrap()
|
||||
.get_or_create_container_idx(&id);
|
||||
let ptr = Arc::downgrade(&self.log_store);
|
||||
a.get_or_create(&id, ptr)?;
|
||||
Ok(
|
||||
a.map_mut(move |x| x.get_mut(&id).unwrap().as_text_mut().unwrap())
|
||||
|
@ -77,7 +84,7 @@ impl LoroCore {
|
|||
&mut self,
|
||||
id: &ContainerID,
|
||||
) -> Result<ContainerRefMut<MapContainer>, LoroError> {
|
||||
let a = OwningRefMut::new(self.container.write());
|
||||
let a = OwningRefMut::new(self.container.write().unwrap());
|
||||
Ok(
|
||||
a.map_mut(move |x| x.get_mut(id).unwrap().as_map_mut().unwrap())
|
||||
.into(),
|
||||
|
@ -89,7 +96,7 @@ impl LoroCore {
|
|||
&mut self,
|
||||
id: &ContainerID,
|
||||
) -> Result<ContainerRefMut<TextContainer>, LoroError> {
|
||||
let a = OwningRefMut::new(self.container.write());
|
||||
let a = OwningRefMut::new(self.container.write().unwrap());
|
||||
Ok(
|
||||
a.map_mut(move |x| x.get_mut(id).unwrap().as_text_mut().unwrap())
|
||||
.into(),
|
||||
|
@ -101,23 +108,23 @@ impl LoroCore {
|
|||
&self,
|
||||
id: &ContainerID,
|
||||
) -> Result<ContainerRef<TextContainer>, LoroError> {
|
||||
let a = OwningRef::new(self.container.read());
|
||||
let a = OwningRef::new(self.container.read().unwrap());
|
||||
Ok(a.map(move |x| x.get(id).unwrap().as_text().unwrap()).into())
|
||||
}
|
||||
|
||||
pub fn export(&self, remote_vv: VersionVector) -> Vec<Change<RemoteOp>> {
|
||||
let store = self.log_store.read();
|
||||
let store = self.log_store.read().unwrap();
|
||||
store.export(&remote_vv)
|
||||
}
|
||||
|
||||
pub fn import(&mut self, changes: Vec<Change<RemoteOp>>) {
|
||||
let mut store = self.log_store.write();
|
||||
let mut store = self.log_store.write().unwrap();
|
||||
store.import(changes)
|
||||
}
|
||||
|
||||
#[cfg(feature = "fuzzing")]
|
||||
pub fn debug_inspect(&self) {
|
||||
self.log_store.write().debug_inspect();
|
||||
self.container.write().debug_inspect();
|
||||
self.log_store.write().unwrap().debug_inspect();
|
||||
self.container.write().unwrap().debug_inspect();
|
||||
}
|
||||
}
|
||||
|
|
24
crates/loro-wasm/web-test/.gitignore
vendored
Normal file
24
crates/loro-wasm/web-test/.gitignore
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
13
crates/loro-wasm/web-test/index.html
Normal file
13
crates/loro-wasm/web-test/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Preact + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
22
crates/loro-wasm/web-test/package.json
Normal file
22
crates/loro-wasm/web-test/package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "web-test",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"loro-wasm": "../pkg",
|
||||
"preact": "^10.11.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@preact/preset-vite": "^2.4.0",
|
||||
"@types/node": "^18.11.9",
|
||||
"typescript": "^4.6.4",
|
||||
"vite": "^3.2.3",
|
||||
"vitest": "^0.24.5"
|
||||
}
|
||||
}
|
1263
crates/loro-wasm/web-test/pnpm-lock.yaml
Normal file
1263
crates/loro-wasm/web-test/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
1
crates/loro-wasm/web-test/public/vite.svg
Normal file
1
crates/loro-wasm/web-test/public/vite.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
25
crates/loro-wasm/web-test/src/app.css
Normal file
25
crates/loro-wasm/web-test/src/app.css
Normal file
|
@ -0,0 +1,25 @@
|
|||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.preact:hover {
|
||||
filter: drop-shadow(0 0 2em #673ab8aa);
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
49
crates/loro-wasm/web-test/src/app.tsx
Normal file
49
crates/loro-wasm/web-test/src/app.tsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { useState, useEffect } from "preact/hooks";
|
||||
import preactLogo from "./assets/preact.svg";
|
||||
import init, { Loro } from "loro-wasm";
|
||||
import "./app.css";
|
||||
|
||||
init();
|
||||
export function App() {
|
||||
const [count, setCount] = useState(0);
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
await init();
|
||||
const loro = new Loro();
|
||||
const a = loro.get_text_container("ha");
|
||||
a.insert(0, "hello world");
|
||||
a.delete(6, 5);
|
||||
a.insert(6, "everyone");
|
||||
console.log(a.get_value());
|
||||
const b = loro.get_map_container("ha");
|
||||
b.set("ab", 123);
|
||||
console.log(b.get_value());
|
||||
console.log(a.get_value());
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<a href="https://vitejs.dev" target="_blank">
|
||||
<img src="/vite.svg" class="logo" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://preactjs.com" target="_blank">
|
||||
<img src={preactLogo} class="logo preact" alt="Preact logo" />
|
||||
</a>
|
||||
</div>
|
||||
<h1>Vite + Preact</h1>
|
||||
<div class="card">
|
||||
<button onClick={() => setCount((count) => count + 1)}>
|
||||
count is {count}
|
||||
</button>
|
||||
<p>
|
||||
Edit <code>src/app.tsx</code> and save to test HMR
|
||||
</p>
|
||||
</div>
|
||||
<p class="read-the-docs">
|
||||
Click on the Vite and Preact logos to learn more
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
1
crates/loro-wasm/web-test/src/assets/preact.svg
Normal file
1
crates/loro-wasm/web-test/src/assets/preact.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="27.68" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 296"><path fill="#673AB8" d="m128 0l128 73.9v147.8l-128 73.9L0 221.7V73.9z"></path><path fill="#FFF" d="M34.865 220.478c17.016 21.78 71.095 5.185 122.15-34.704c51.055-39.888 80.24-88.345 63.224-110.126c-17.017-21.78-71.095-5.184-122.15 34.704c-51.055 39.89-80.24 88.346-63.224 110.126Zm7.27-5.68c-5.644-7.222-3.178-21.402 7.573-39.253c11.322-18.797 30.541-39.548 54.06-57.923c23.52-18.375 48.303-32.004 69.281-38.442c19.922-6.113 34.277-5.075 39.92 2.148c5.644 7.223 3.178 21.403-7.573 39.254c-11.322 18.797-30.541 39.547-54.06 57.923c-23.52 18.375-48.304 32.004-69.281 38.441c-19.922 6.114-34.277 5.076-39.92-2.147Z"></path><path fill="#FFF" d="M220.239 220.478c17.017-21.78-12.169-70.237-63.224-110.126C105.96 70.464 51.88 53.868 34.865 75.648c-17.017 21.78 12.169 70.238 63.224 110.126c51.055 39.889 105.133 56.485 122.15 34.704Zm-7.27-5.68c-5.643 7.224-19.998 8.262-39.92 2.148c-20.978-6.437-45.761-20.066-69.28-38.441c-23.52-18.376-42.74-39.126-54.06-57.923c-10.752-17.851-13.218-32.03-7.575-39.254c5.644-7.223 19.999-8.261 39.92-2.148c20.978 6.438 45.762 20.067 69.281 38.442c23.52 18.375 42.739 39.126 54.06 57.923c10.752 17.85 13.218 32.03 7.574 39.254Z"></path><path fill="#FFF" d="M127.552 167.667c10.827 0 19.603-8.777 19.603-19.604c0-10.826-8.776-19.603-19.603-19.603c-10.827 0-19.604 8.777-19.604 19.603c0 10.827 8.777 19.604 19.604 19.604Z"></path></svg>
|
After Width: | Height: | Size: 1.6 KiB |
70
crates/loro-wasm/web-test/src/index.css
Normal file
70
crates/loro-wasm/web-test/src/index.css
Normal file
|
@ -0,0 +1,70 @@
|
|||
:root {
|
||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
5
crates/loro-wasm/web-test/src/main.tsx
Normal file
5
crates/loro-wasm/web-test/src/main.tsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { render } from 'preact'
|
||||
import { App } from './app'
|
||||
import './index.css'
|
||||
|
||||
render(<App />, document.getElementById('app') as HTMLElement)
|
1
crates/loro-wasm/web-test/src/vite-env.d.ts
vendored
Normal file
1
crates/loro-wasm/web-test/src/vite-env.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/// <reference types="vite/client" />
|
22
crates/loro-wasm/web-test/tsconfig.json
Normal file
22
crates/loro-wasm/web-test/tsconfig.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
9
crates/loro-wasm/web-test/tsconfig.node.json
Normal file
9
crates/loro-wasm/web-test/tsconfig.node.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
14
crates/loro-wasm/web-test/vite.config.ts
Normal file
14
crates/loro-wasm/web-test/vite.config.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { defineConfig } from "vite";
|
||||
import preact from "@preact/preset-vite";
|
||||
import path from "path";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [preact()],
|
||||
server: {
|
||||
fs: {
|
||||
// Allow serving files from one level up to the project root
|
||||
allow: [".."],
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Reference in a new issue