Skip to content

Commit

Permalink
Merge pull request #42 from BrowserSync/reactive-client
Browse files Browse the repository at this point in the history
reactive-client
  • Loading branch information
shakyShane authored Nov 17, 2024
2 parents 189e4b1 + ef1b23c commit 46c53e4
Show file tree
Hide file tree
Showing 52 changed files with 1,739 additions and 1,350 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ jobs:
- name: Build Rust Binary with napi
run: npm run build:debug

- name: Check tree is clean
run: bash ./clean-tree.sh

- name: Npm test (binary)
run: npm run test:build

- name: Npm run build:client
run: npm run build:client

- name: Npm run build:example
run: npm run build:example

Expand Down
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ui/dist
inject/dist
inject/vendor
generated/
2 changes: 2 additions & 0 deletions bslive.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
servers:
- bind_address: 0.0.0.0:3000
clients:
log: trace
routes:
- path: /
dir: examples/basic/public
Expand Down
5 changes: 5 additions & 0 deletions clean-tree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -euxo pipefail

git update-index --refresh
git diff-index --patch-with-raw HEAD --
git diff-index --quiet HEAD --
15 changes: 7 additions & 8 deletions crates/bsnext_core/src/server/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use axum::response::{IntoResponse, Response};
use axum::routing::{get, MethodRouter};
use axum::{http, middleware, Extension, Router};

use crate::meta::MetaData;
use crate::server::router::assets::pub_ui_assets;
use crate::server::router::pub_api::pub_api;
use crate::server::state::ServerState;
use crate::ws::ws_handler;
use axum::body::Body;
use bsnext_client::html_with_base;
use bsnext_dto::{RouteDTO, ServerDesc};
use http::header::CONTENT_TYPE;
use http::{HeaderValue, StatusCode};
use hyper_tls::HttpsConnector;
Expand All @@ -19,14 +26,6 @@ use mime_guess::mime;
use std::sync::Arc;
use tower::{ServiceBuilder, ServiceExt};
use tower_http::catch_panic::CatchPanicLayer;

use crate::meta::MetaData;
use crate::server::router::assets::pub_ui_assets;
use crate::server::router::pub_api::pub_api;
use crate::server::state::ServerState;
use crate::ws::ws_handler;
use bsnext_client::html_with_base;
use bsnext_dto::{RouteDTO, ServerDesc};
use tracing::{span, Level};

mod assets;
Expand Down
3 changes: 3 additions & 0 deletions crates/bsnext_core/src/server/router/pub_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ async fn post_events(
ClientEvent::Config(_) => {
todo!("handle ClientEvent::Config in incoming event handler...")
}
ClientEvent::WsConnection(_) => {
todo!("handle ClientEvent::WsConnection in incoming event handler?")
}
};
match recv
.send(IncomingEvents::FilesChanged(FilesChanged {
Expand Down
2 changes: 1 addition & 1 deletion crates/bsnext_core/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn handle_socket(
let mut send_task = tokio::spawn(async move {
// send client config first
let v = initial_config.read().await;
let as_client_event = ClientEvent::Config(v.clone().into());
let as_client_event = ClientEvent::WsConnection(v.clone().into());
let as_str = serde_json::to_string(&as_client_event).unwrap();
drop(v);

Expand Down
1 change: 1 addition & 0 deletions crates/bsnext_dto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl From<InputError> for InputErrorDTO {
#[serde(tag = "kind", content = "payload")]
pub enum ClientEvent {
Change(ChangeDTO),
WsConnection(ClientConfigDTO),
Config(ClientConfigDTO),
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bsnext_input/src/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ fn playground_wrap() -> InjectOpts {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Document</title>
<title>Browsersync Live - Playground</title>
<link rel="stylesheet" href="/__bslive_playground.css">
</head>
<body>
"#;
let append = r#"
<script src="/__bslive_playground.js"></script>
<script src="/__bslive_playground.js" type="module"></script>
</body>
</html>
"#;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ expression: routes
},
kind: Raw(
Raw {
raw: "/*\n 1. Use a more-intuitive box-sizing model.\n*/\n*, *::before, *::after {\n box-sizing: border-box;\n}\n\n/*\n 2. Remove default margin\n*/\n* {\n margin: 0;\n}\n\n/*\n Typographic tweaks!\n 3. Add accessible line-height\n 4. Improve text rendering\n*/\nbody {\n line-height: 1.5;\n -webkit-font-smoothing: antialiased;\n}\n\n/*\n 5. Improve media defaults\n*/\nimg, picture, video, canvas, svg {\n display: block;\n max-width: 100%;\n}\n\n/*\n 6. Remove built-in form typography styles\n*/\ninput, button, textarea, select {\n font: inherit;\n}\n\n/*\n 7. Avoid text overflows\n*/\np, h1, h2, h3, h4, h5, h6 {\n overflow-wrap: break-word;\n}\n\n/*\n 8. Create a root stacking context\n*/\n#root, #__next {\n isolation: isolate;\n}",
raw: "/*\n 1. Use a more-intuitive box-sizing model.\n*/\n*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n/*\n 2. Remove default margin\n*/\n* {\n margin: 0;\n}\n\n/*\n Typographic tweaks!\n 3. Add accessible line-height\n 4. Improve text rendering\n*/\nbody {\n line-height: 1.5;\n -webkit-font-smoothing: antialiased;\n}\n\n/*\n 5. Improve media defaults\n*/\nimg,\npicture,\nvideo,\ncanvas,\nsvg {\n display: block;\n max-width: 100%;\n}\n\n/*\n 6. Remove built-in form typography styles\n*/\ninput,\nbutton,\ntextarea,\nselect {\n font: inherit;\n}\n\n/*\n 7. Avoid text overflows\n*/\np,\nh1,\nh2,\nh3,\nh4,\nh5,\nh6 {\n overflow-wrap: break-word;\n}\n\n/*\n 8. Create a root stacking context\n*/\n#root,\n#__next {\n isolation: isolate;\n}\n",
},
),
opts: Opts {
Expand Down
2 changes: 1 addition & 1 deletion examples/openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"no test specified\"",
"start": "node --env-file .env build.mjs",
"build:client": "node build.mjs"
"build:example": "node build.mjs"
},
"keywords": [],
"author": "",
Expand Down
1 change: 1 addition & 0 deletions generated/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export type InputErrorDTO =

export type ClientEvent =
| { kind: "Change", payload: ChangeDTO }
| { kind: "WsConnection", payload: ClientConfigDTO }
| { kind: "Config", payload: ClientConfigDTO };

export type ChangeDTO =
Expand Down
4 changes: 4 additions & 0 deletions generated/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ var clientEventSchema = z.union([
kind: z.literal("Change"),
payload: changeDTOSchema
}),
z.object({
kind: z.literal("WsConnection"),
payload: clientConfigDTOSchema
}),
z.object({
kind: z.literal("Config"),
payload: clientConfigDTOSchema
Expand Down
Loading

0 comments on commit 46c53e4

Please sign in to comment.