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

WIP for a Kobold router #95

Merged
merged 1 commit into from
Apr 10, 2024
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
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
Loading