-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize array key_path code to fix errors found in testing with a …
…real-world app (#12) * removed unncessary match statement * create keypath enum to separate logic for single and array key paths
- Loading branch information
1 parent
47b1256
commit ac023a3
Showing
4 changed files
with
45 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use js_sys::Array; | ||
use wasm_bindgen::prelude::*; | ||
|
||
pub(crate) enum KeyPath { | ||
String(String), | ||
Array(Vec<String>), | ||
} | ||
|
||
impl KeyPath { | ||
pub fn new_str(key_path: &str) -> Self { | ||
Self::String(key_path.to_owned()) | ||
} | ||
|
||
pub fn new_array<'a>(key_path_array: impl IntoIterator<Item = &'a str>) -> Self { | ||
Self::Array(key_path_array.into_iter().map(ToOwned::to_owned).collect()) | ||
} | ||
} | ||
|
||
impl From<KeyPath> for JsValue { | ||
fn from(key_path: KeyPath) -> Self { | ||
match key_path { | ||
KeyPath::String(key_path) => JsValue::from_str(&key_path), | ||
KeyPath::Array(key_path_array) => { | ||
let key_path = key_path_array | ||
.iter() | ||
.map(|s| JsValue::from_str(s)) | ||
.collect::<Array>(); | ||
key_path.into() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ | |
mod direction; | ||
mod error; | ||
mod index; | ||
mod key_path; | ||
mod key_range; | ||
mod object_store; | ||
mod request; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters