Skip to content

Commit

Permalink
Kobold Router
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfingers23 committed Apr 10, 2024
1 parent 70db885 commit 7afc92e
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ examples/*/dist
examples/*/Cargo.lock
crates/*/Cargo.lock
.DS_Store
.idea
134 changes: 85 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions crates/kobold_router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "kobold_router"
version = "0.1.0"
authors = ["Bailey Townsend"]
edition = "2021"
license = "MPL-2.0"
readme = "../../README.md"
keywords = ["web", "wasm", "router", "kobold"]
categories = ["wasm", "web-programming"]
description = "A router for web applications written with Kobold"
repository = "https://github.com/maciejhirsz/kobold"
documentation = "https://docs.rs/kobold"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
kobold = { path = "../kobold" }
matchit = "0.8.0"
serde = { version = "1.0.197", features = ["derive"] }
serde-wasm-bindgen = "0.4"
wasm-bindgen = "0.2.84"

[dependencies.web-sys]
version = "0.3"
features = ["Window", "Location", "History"]
19 changes: 19 additions & 0 deletions crates/kobold_router/js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function changeRouteView(view) {
const routerView = document.getElementById("routerView");
routerView.innerHTML = "";
routerView.appendChild(view);
}

export function setupPushStateEvent() {
let _wr = function (type) {
let orig = history[type];
return function () {
let rv = orig.apply(this, arguments);
let e = new Event(type);
e.arguments = arguments;
window.dispatchEvent(e);
return rv;
};
};
history.pushState = _wr('pushState');
}
10 changes: 10 additions & 0 deletions crates/kobold_router/src/internal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "/js/util.js")]
extern "C" {
#[wasm_bindgen(js_name = "changeRouteView")]
pub(crate) fn change_route_view(view: &JsValue);

#[wasm_bindgen(js_name = "setupPushStateEvent")]
pub(crate) fn setup_push_state_event();
}
Loading

0 comments on commit 7afc92e

Please sign in to comment.