Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasm example code #11

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Its goal is to be as dependency-less as possible in order to be easily compiled

#### REQUIREMENTS

- Rust toolchain
- **The Rust Toolchain**

Rust toolchain can be installed by following the instructions [here](https://doc.rust-lang.org/cargo/getting-started/installation.html)
Follow the instructions [here](https://doc.rust-lang.org/cargo/getting-started/installation.html) to install the official Rust toolchain.

- WebAssembly toolchain
- **The WebAssembly Toolchain**

We need to build the project in WebAssembly. To do so, we need to install `wasm-pack` and tweak Rust toolchain context.
If yous are interested in compiling the project for WebAssembly, you can follow the instructions below.

<details>
<summary>Read more</summary>
Expand All @@ -65,7 +65,7 @@ Its goal is to be as dependency-less as possible in order to be easily compiled

</details>

- **wnfs** script
- **The _wnfs_ Helper Script**

If you are on a Unix platform, you can optionally install the `wnfs` script.

Expand Down
36 changes: 4 additions & 32 deletions crates/fs/public/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ impl PublicDirectory {
let mut working_node = Some(Rc::clone(&root_node));

// The nodes along the path specified.
let mut path_nodes: Vec<(String, Shared<PublicNode>)> = if !path_segments.is_empty() {
vec![(String::new(), Rc::clone(&root_node))]
} else {
vec![]
};
let mut path_nodes: Vec<(String, Shared<PublicNode>)> =
vec![(String::new(), Rc::clone(&root_node))];

// Iterate over the path segments.
for (index, segment) in path_segments.iter().enumerate() {
Expand Down Expand Up @@ -360,7 +357,7 @@ impl PublicDirectory {
}

// If directory does not already exist or `diverge_anyway` is set, we create a divergent path.
let (root_node, working_node) = if !dir_exists || diverge_anyway {
let (root_node, working_node) = if diverge_anyway || !dir_exists {
let diverged_nodes = utils::diverge_and_patch(path_nodes);
if !diverged_nodes.is_empty() {
(
Expand Down Expand Up @@ -594,7 +591,7 @@ mod utils {
use std::rc::Rc;

use crate::{
public::{Id, Link, PublicNode},
public::{Link, PublicNode},
shared, Shared,
};

Expand Down Expand Up @@ -873,29 +870,4 @@ mod public_directory_tests {

assert!(result.is_err());
}

#[async_std::test]
async fn read_can_fetch_userland_of_file_added_to_directory() {
let root_dir = PublicDirectory::new(Utc::now());

let mut store = MemoryBlockStore::default();

let content_cid = Cid::default();

let time = Utc::now();

let OpResult { root_node, .. } = root_dir
.write(&["text.txt".into()], content_cid, time, &store)
.await
.unwrap();

let OpResult { result, .. } = root_node
.borrow()
.as_dir()
.read(&["text.txt".into()], &mut store)
.await
.unwrap();

assert_eq!(result, content_cid);
}
}
12 changes: 7 additions & 5 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
wasm-pack build --target web
```

## Testing the Project
## Trying the Examples

- Start the test
- Run server

```bash
wasm-pack test --chrome
npx http-server -p 8080
```

- Run tests in the browser
- Visit the following pages:

```bash
open http://127.0.0.1:8000
open http://localhost:8080/examples/graph/
```

NOTE: Examples will be moved into separate projects in the future.
153 changes: 0 additions & 153 deletions crates/wasm/examples/common/index.css

This file was deleted.

Loading