Expose to JS
This commit is contained in:
parent
450eaaff05
commit
1b46e5d237
9 changed files with 95 additions and 17 deletions
|
|
@ -170,7 +170,7 @@
|
|||
//! &changes.into()
|
||||
//! );
|
||||
//!
|
||||
//! let serialized = serde_yaml::to_string(&result.serialise_as_change_set()).unwrap();
|
||||
//! let serialized = serde_yaml::to_string(&result.to_change_set()).unwrap();
|
||||
//! assert_eq!(
|
||||
//! serialized,
|
||||
//! concat!(
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ where
|
|||
/// This is useful for sending changes over the network if there's
|
||||
/// a clear consensus on the original text.
|
||||
#[must_use]
|
||||
pub fn serialise_as_change_set(&self) -> ChangeSet {
|
||||
pub fn to_change_set(&self) -> ChangeSet {
|
||||
ChangeSet::new(
|
||||
SimpleOperation::from_operations(&self.operations),
|
||||
self.cursors.clone(),
|
||||
|
|
@ -428,7 +428,7 @@ mod tests {
|
|||
let original = "Merging text is hard!";
|
||||
let changes = "Merging text is easy with reconcile!";
|
||||
let result = EditedText::from_strings(original, &changes.into());
|
||||
let serialized = serde_yaml::to_string(&result.serialise_as_change_set()).unwrap();
|
||||
let serialized = serde_yaml::to_string(&result.to_change_set()).unwrap();
|
||||
|
||||
let expected = concat!(
|
||||
"operations:\n",
|
||||
|
|
@ -448,7 +448,7 @@ mod tests {
|
|||
|
||||
let edited_text = EditedText::from_strings(original, &updated.into());
|
||||
|
||||
let change_set = edited_text.serialise_as_change_set();
|
||||
let change_set = edited_text.to_change_set();
|
||||
let deserialized_edited_text =
|
||||
EditedText::from_change_set(original, change_set, &*BuiltinTokenizer::Word);
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ impl<'de> Deserialize<'de> for SimpleOperation {
|
|||
type Value = SimpleOperation;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("an integer between -2^64 and 2^63 or a string")
|
||||
formatter.write_str("an integer between -2^63 and 2^64-1 or a string")
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
|
||||
|
|
|
|||
19
src/wasm.rs
19
src/wasm.rs
|
|
@ -87,6 +87,25 @@ pub fn generic_reconcile(
|
|||
}
|
||||
}
|
||||
|
||||
/// WASM wrapper around getting a compact diff representation as a JSON string
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If serialization to JSON fails which should not happen
|
||||
#[wasm_bindgen(js_name = getCompactDiff)]
|
||||
#[must_use]
|
||||
pub fn get_compact_diff(
|
||||
parent: &str,
|
||||
changed: &TextWithCursors,
|
||||
tokenizer: BuiltinTokenizer,
|
||||
) -> String {
|
||||
set_panic_hook();
|
||||
let edited_text = crate::EditedText::from_strings_with_tokenizer(parent, changed, &*tokenizer);
|
||||
let change_set = edited_text.to_change_set();
|
||||
|
||||
serde_json::to_string(&change_set).expect("Failed to serialize change set")
|
||||
}
|
||||
|
||||
/// Heuristically determine if the given data is a binary or a text file's
|
||||
/// content.
|
||||
#[wasm_bindgen(js_name = isBinary)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue