mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
refactor: rm deprecated
This commit is contained in:
parent
08c462ba35
commit
e3d6d1b175
@ -97,7 +97,7 @@ fn updateRows(_: *zx.client.Event) void {
|
||||
var i: usize = 0;
|
||||
while (i < items.items.len) : (i += 10) {
|
||||
const item = &items.items[i];
|
||||
const new_label = std.fmt.allocPrint(zx.client_allocator, "{s} !!!", .{item.label}) catch @panic("OOM");
|
||||
const new_label = std.fmt.allocPrint(zx.allocator, "{s} !!!", .{item.label}) catch @panic("OOM");
|
||||
item.label = new_label;
|
||||
}
|
||||
zx.client.rerender();
|
||||
@ -166,7 +166,7 @@ fn BuildRows(count_to_add: u32, clear_first: bool) void {
|
||||
}
|
||||
|
||||
for (0..count_to_add) |_| {
|
||||
const label = std.fmt.allocPrint(zx.client_allocator, "{s} {s} {s}", .{
|
||||
const label = std.fmt.allocPrint(zx.allocator, "{s} {s} {s}", .{
|
||||
adjectives[RandomNumber(adjectives.len)],
|
||||
colours[RandomNumber(colours.len)],
|
||||
nouns[RandomNumber(nouns.len)],
|
||||
@ -176,7 +176,7 @@ fn BuildRows(count_to_add: u32, clear_first: bool) void {
|
||||
.label = label,
|
||||
};
|
||||
|
||||
items.append(zx.client_allocator, item) catch @panic("OOM");
|
||||
items.append(zx.allocator, item) catch @panic("OOM");
|
||||
next_id += 1;
|
||||
}
|
||||
|
||||
|
||||
@ -40,9 +40,9 @@ fn settingsKV() zx.kv.KVScope {
|
||||
|
||||
pub fn loadSettings() bool {
|
||||
if (_show_native_elements_loaded) return true;
|
||||
show_native_elements = settingsKV().as(zx.client_allocator, storage_key, bool) catch null orelse true;
|
||||
host = settingsKV().get(zx.client_allocator, host_storage_key) catch null orelse host;
|
||||
current_path = settingsKV().get(zx.client_allocator, path_storage_key) catch null orelse current_path;
|
||||
show_native_elements = settingsKV().as(zx.allocator, storage_key, bool) catch null orelse true;
|
||||
host = settingsKV().get(zx.allocator, host_storage_key) catch null orelse host;
|
||||
current_path = settingsKV().get(zx.allocator, path_storage_key) catch null orelse current_path;
|
||||
_show_native_elements_loaded = true;
|
||||
return _show_native_elements_loaded;
|
||||
}
|
||||
@ -53,7 +53,7 @@ pub fn saveSettings() void {
|
||||
}
|
||||
|
||||
pub fn loadThemeIsDark() bool {
|
||||
return settingsKV().as(zx.client_allocator, theme_storage_key, bool) catch null orelse true;
|
||||
return settingsKV().as(zx.allocator, theme_storage_key, bool) catch null orelse true;
|
||||
}
|
||||
|
||||
pub fn saveThemeIsDark(dark: bool) void {
|
||||
|
||||
@ -14,26 +14,26 @@ fn fetchComponentsCount() void {
|
||||
if (components_fetch_started) return;
|
||||
const host = data.host;
|
||||
const path = data.current_path;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.client_allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.client_allocator, "{s}/.well-known/_zx/devtool?path={s}", .{ base, path }) catch return;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.allocator, "{s}/.well-known/_zx/devtool?path={s}", .{ base, path }) catch return;
|
||||
components_fetch_started = true;
|
||||
_ = zx.fetch(.wasm(&onFetchComponentsCount), zx.client_allocator, url, .{ .method = .GET }) catch {};
|
||||
_ = zx.fetch(.wasm(&onFetchComponentsCount), zx.allocator, url, .{ .method = .GET }) catch {};
|
||||
}
|
||||
|
||||
fn fetchRoutesCount() void {
|
||||
if (routes_fetch_started) return;
|
||||
const host = data.host;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.client_allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.client_allocator, "{s}/.well-known/_zx/devtool?meta=true", .{base}) catch return;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.allocator, "{s}/.well-known/_zx/devtool?meta=true", .{base}) catch return;
|
||||
routes_fetch_started = true;
|
||||
_ = zx.fetch(.wasm(&onFetchRoutesCount), zx.client_allocator, url, .{ .method = .GET }) catch {};
|
||||
_ = zx.fetch(.wasm(&onFetchRoutesCount), zx.allocator, url, .{ .method = .GET }) catch {};
|
||||
}
|
||||
|
||||
fn onFetchComponentsCount(res: ?*zx.Fetch.Response, _: ?zx.Fetch.FetchError) void {
|
||||
if (res) |r| {
|
||||
defer r.deinit();
|
||||
if (r.text()) |p| {
|
||||
const parsed = zx.util.zxon.parse(zx.Component.Serializable, zx.client_allocator, p, .{}) catch return;
|
||||
const parsed = zx.util.zxon.parse(zx.Component.Serializable, zx.allocator, p, .{}) catch return;
|
||||
overview_component_count = countSerializable(parsed.children orelse &.{}, 0);
|
||||
} else |_| {}
|
||||
}
|
||||
@ -63,7 +63,7 @@ fn onFetchRoutesCount(res: ?*zx.Fetch.Response, _: ?zx.Fetch.FetchError) void {
|
||||
if (res) |r| {
|
||||
defer r.deinit();
|
||||
if (r.text()) |p| {
|
||||
const parsed = zx.util.zxon.parse([]const AppRoute, zx.client_allocator, p, .{}) catch return;
|
||||
const parsed = zx.util.zxon.parse([]const AppRoute, zx.allocator, p, .{}) catch return;
|
||||
overview_route_count = parsed.len;
|
||||
} else |_| {}
|
||||
}
|
||||
|
||||
@ -27,20 +27,20 @@ fn fetch() void {
|
||||
if (!data.loadSettings()) return;
|
||||
const host = data.host;
|
||||
const path = data.current_path;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.client_allocator, "http://{s}", .{host}) catch return;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.allocator, "http://{s}", .{host}) catch return;
|
||||
const include_native = if (data.show_native_elements) "1" else "0";
|
||||
const url = std.fmt.allocPrint(zx.client_allocator, "{s}/.well-known/_zx/devtool?path={s}&include_native={s}", .{ base, path, include_native }) catch return;
|
||||
const url = std.fmt.allocPrint(zx.allocator, "{s}/.well-known/_zx/devtool?path={s}&include_native={s}", .{ base, path, include_native }) catch return;
|
||||
fetched = true;
|
||||
_ = zx.fetch(.wasm(&onFetchText), zx.client_allocator, url, .{ .method = .GET }) catch {};
|
||||
_ = zx.fetch(.wasm(&onFetchText), zx.allocator, url, .{ .method = .GET }) catch {};
|
||||
}
|
||||
|
||||
fn onFetchText(res: ?*zx.Fetch.Response, _: ?zx.Fetch.FetchError) void {
|
||||
if (res) |r| {
|
||||
defer r.deinit();
|
||||
if (r.text()) |p| {
|
||||
const parsed = zx.util.zxon.parse(zx.Component.Serializable, zx.client_allocator, p, .{}) catch return;
|
||||
const parsed = zx.util.zxon.parse(zx.Component.Serializable, zx.allocator, p, .{}) catch return;
|
||||
if (parsed.children) |sc| {
|
||||
const mapped = data.fromSerializableSlice(zx.client_allocator, sc) catch unreachable;
|
||||
const mapped = data.fromSerializableSlice(zx.allocator, sc) catch unreachable;
|
||||
std.log.info("Fetched {d} components", .{mapped.len});
|
||||
components = mapped;
|
||||
}
|
||||
|
||||
@ -28,10 +28,10 @@ fn fetch() void {
|
||||
if (fetched) return;
|
||||
if (!data.loadSettings()) return;
|
||||
const host = data.host;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.client_allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.client_allocator, "{s}/.well-known/_zx/devtool?meta=true", .{base}) catch return;
|
||||
const base = if (std.mem.startsWith(u8, host, "http://") or std.mem.startsWith(u8, host, "https://")) host else std.fmt.allocPrint(zx.allocator, "http://{s}", .{host}) catch return;
|
||||
const url = std.fmt.allocPrint(zx.allocator, "{s}/.well-known/_zx/devtool?meta=true", .{base}) catch return;
|
||||
fetched = true;
|
||||
_ = zx.fetch(.wasm(&onFetchText), zx.client_allocator, url, .{ .method = .GET }) catch {};
|
||||
_ = zx.fetch(.wasm(&onFetchText), zx.allocator, url, .{ .method = .GET }) catch {};
|
||||
}
|
||||
|
||||
pub const AppRoute = struct {
|
||||
@ -47,7 +47,7 @@ fn onFetchText(res: ?*zx.Fetch.Response, _: ?zx.Fetch.FetchError) void {
|
||||
if (res) |r| {
|
||||
defer r.deinit();
|
||||
if (r.text()) |p| {
|
||||
routes = zx.util.zxon.parse([]const AppRoute, zx.client_allocator, p, .{}) catch return;
|
||||
routes = zx.util.zxon.parse([]const AppRoute, zx.allocator, p, .{}) catch return;
|
||||
} else |_| {}
|
||||
}
|
||||
zx.client.rerender();
|
||||
|
||||
@ -212,7 +212,7 @@ fn currentThemeIsDark() bool {
|
||||
fn applyTheme(dark: bool) void {
|
||||
if (zx.platform.role != .client) return;
|
||||
|
||||
const document = zx.client.Document.init(zx.client_allocator);
|
||||
const document = zx.client.Document.init(zx.allocator);
|
||||
defer document.deinit();
|
||||
|
||||
const root = document.querySelector("html") catch return;
|
||||
@ -276,7 +276,7 @@ pub fn HostSetting(ctx: *zx.ComponentCtx(HostSettingProps)) zx.Component {
|
||||
|
||||
pub fn handleHostInput(ctx: zx.client.Event) void {
|
||||
if (ctx.value()) |val| {
|
||||
data.host = zx.client_allocator.dupe(u8, val) catch val;
|
||||
data.host = zx.allocator.dupe(u8, val) catch val;
|
||||
data.saveSettings();
|
||||
zx.client.rerender();
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ fn init(count: *zx.State(u64)) !void {
|
||||
return;
|
||||
|
||||
initialized = true;
|
||||
const prev = try zx.kv.as(zx.client_allocator, "c", u64);
|
||||
const prev = try zx.kv.as(zx.allocator, "c", u64);
|
||||
const count_value = if (prev) |s| s else 0;
|
||||
zx.log.info("Initializing count: {d}\n", .{count_value});
|
||||
count.set(count_value);
|
||||
@ -48,7 +48,7 @@ fn tryonclick(ctx: *zx.client.Event.Stateful) !void {
|
||||
|
||||
const count_state = ctx.state(u64);
|
||||
|
||||
const prev = try zx.kv.as(zx.client_allocator, "c", u64);
|
||||
const prev = try zx.kv.as(zx.allocator, "c", u64);
|
||||
const count = if (prev) |s| s + 1 else 1;
|
||||
try zx.kv.putAs("c", count, .{});
|
||||
count_state.set(count);
|
||||
|
||||
@ -101,8 +101,8 @@ fn joinChat(username: []const u8) void {
|
||||
if (zx.platform.role != .client) return;
|
||||
|
||||
std.log.info("joinChat: {s}", .{username});
|
||||
current_username = zx.client_allocator.dupe(u8, username) catch return;
|
||||
ws = zx.WebSocket.init(zx.client_allocator, "/examples/realtime/ws", .{}) catch return;
|
||||
current_username = zx.allocator.dupe(u8, username) catch return;
|
||||
ws = zx.WebSocket.init(zx.allocator, "/examples/realtime/ws", .{}) catch return;
|
||||
|
||||
if (ws) |*w| {
|
||||
w.onopen = &onWsOpen;
|
||||
@ -129,12 +129,12 @@ fn leaveChat(_: zx.client.Event) void {
|
||||
|
||||
if (messages) |msgs_state| {
|
||||
var msgs = msgs_state.get();
|
||||
msgs.deinit(zx.client_allocator);
|
||||
msgs.deinit(zx.allocator);
|
||||
msgs_state.set(.{});
|
||||
}
|
||||
|
||||
// Clear input via DOM
|
||||
const document = zx.client.Document.init(zx.client_allocator);
|
||||
const document = zx.client.Document.init(zx.allocator);
|
||||
if (document.getElementById("message-input")) |input| {
|
||||
input.ref.set("value", zx.Client.js.string("")) catch {};
|
||||
} else |_| {}
|
||||
@ -144,9 +144,9 @@ fn sendMessage(e: zx.client.Event) void {
|
||||
if (zx.platform.role != .client) return;
|
||||
e.preventDefault();
|
||||
|
||||
const document = zx.client.Document.init(zx.client_allocator);
|
||||
const document = zx.client.Document.init(zx.allocator);
|
||||
const input = document.getElementById("message-input") catch return;
|
||||
const text = input.ref.getAlloc(zx.Client.js.String, zx.client_allocator, "value") catch return;
|
||||
const text = input.ref.getAlloc(zx.Client.js.String, zx.allocator, "value") catch return;
|
||||
|
||||
std.log.info("sendMessage: {s}", .{text});
|
||||
if (text.len == 0) return;
|
||||
@ -171,15 +171,15 @@ fn onWsMessage(_: *zx.WebSocket, event: zx.WebSocket.MessageEvent) void {
|
||||
var text: []const u8 = data;
|
||||
|
||||
if (std.mem.indexOf(u8, data, ": ")) |colon_idx| {
|
||||
username = zx.client_allocator.dupe(u8, data[0..colon_idx]) catch return;
|
||||
text = zx.client_allocator.dupe(u8, data[colon_idx + 2 ..]) catch return;
|
||||
username = zx.allocator.dupe(u8, data[0..colon_idx]) catch return;
|
||||
text = zx.allocator.dupe(u8, data[colon_idx + 2 ..]) catch return;
|
||||
} else {
|
||||
text = zx.client_allocator.dupe(u8, data) catch return;
|
||||
text = zx.allocator.dupe(u8, data) catch return;
|
||||
}
|
||||
|
||||
if (messages) |msgs_state| {
|
||||
var msgs = msgs_state.get();
|
||||
msgs.insert(zx.client_allocator, 0, .{
|
||||
msgs.insert(zx.allocator, 0, .{
|
||||
.username = username,
|
||||
.text = text,
|
||||
.is_system = is_system,
|
||||
@ -193,7 +193,7 @@ fn onWsClose(_: *zx.WebSocket, _: zx.WebSocket.CloseEvent) void {
|
||||
|
||||
if (messages) |msgs_state| {
|
||||
var msgs = msgs_state.get();
|
||||
msgs.insert(zx.client_allocator, 0, .{
|
||||
msgs.insert(zx.allocator, 0, .{
|
||||
.username = "",
|
||||
.text = "Disconnected from server",
|
||||
.is_system = true,
|
||||
@ -207,7 +207,7 @@ fn onWsError(_: *zx.WebSocket, _: zx.WebSocket.ErrorEvent) void {
|
||||
|
||||
if (messages) |msgs_state| {
|
||||
var msgs = msgs_state.get();
|
||||
msgs.insert(zx.client_allocator, 0, .{
|
||||
msgs.insert(zx.allocator, 0, .{
|
||||
.username = "",
|
||||
.text = "Connection error",
|
||||
.is_system = true,
|
||||
|
||||
@ -104,7 +104,7 @@ fn doFetch(_: zx.client.Event) void {
|
||||
|
||||
_ = zx.fetch(
|
||||
.wasm(&onFetchComplete),
|
||||
zx.client_allocator,
|
||||
zx.allocator,
|
||||
"https://jsonplaceholder.typicode.com/todos/1",
|
||||
.{},
|
||||
) catch |err| {
|
||||
|
||||
@ -90,16 +90,16 @@ fn addTodo(e: *zx.client.Event.Stateful) void {
|
||||
const todos_state = e.state(TodoList);
|
||||
const id_state = e.state(u32);
|
||||
|
||||
const document = zx.client.Document.init(zx.client_allocator);
|
||||
const document = zx.client.Document.init(zx.allocator);
|
||||
const input = document.getElementById("todo-input") catch return;
|
||||
const text = input.ref.getAlloc(js.String, zx.client_allocator, "value") catch return;
|
||||
const text = input.ref.getAlloc(js.String, zx.allocator, "value") catch return;
|
||||
if (text.len == 0) return;
|
||||
|
||||
const id = id_state.get();
|
||||
id_state.set(id + 1);
|
||||
|
||||
var list = todos_state.get();
|
||||
list.append(zx.client_allocator, .{ .id = id, .text = text, .completed = false }) catch return;
|
||||
list.append(zx.allocator, .{ .id = id, .text = text, .completed = false }) catch return;
|
||||
todos_state.set(list);
|
||||
|
||||
input.ref.set("value", js.string("")) catch return;
|
||||
@ -115,7 +115,7 @@ fn toggleTodo(e: *zx.client.Event.Stateful) void {
|
||||
var id: ?u32 = null;
|
||||
if (event.getTarget()) |target| {
|
||||
defer target.deinit();
|
||||
if (target.getAlloc(js.String, zx.client_allocator, "value") catch null) |v| {
|
||||
if (target.getAlloc(js.String, zx.allocator, "value") catch null) |v| {
|
||||
id = std.fmt.parseInt(u32, v, 10) catch null;
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ fn deleteTodo(e: *zx.client.Event.Stateful) void {
|
||||
var id: ?u32 = null;
|
||||
if (event.getTarget()) |target| {
|
||||
defer target.deinit();
|
||||
if (target.getAlloc(js.String, zx.client_allocator, "value") catch null) |v| {
|
||||
if (target.getAlloc(js.String, zx.allocator, "value") catch null) |v| {
|
||||
id = std.fmt.parseInt(u32, v, 10) catch null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ fn reset(_: zx.client.Event) void {
|
||||
|
||||
fn fetch() void {
|
||||
running.set(true);
|
||||
_ = zx.fetch(.wasm(&onFetch), zx.client_allocator, "/examples/wasm/progress", .{ .method = .POST }) catch {};
|
||||
_ = zx.fetch(.wasm(&onFetch), zx.allocator, "/examples/wasm/progress", .{ .method = .POST }) catch {};
|
||||
}
|
||||
|
||||
fn onFetch(res: ?*zx.Fetch.Response, _: ?zx.Fetch.FetchError) void {
|
||||
|
||||
@ -165,18 +165,18 @@ fn handleRunClick(ctx: zx.client.Event) void {
|
||||
|
||||
if (zx.platform.role != .client) return;
|
||||
|
||||
const document = zx.client.Document.init(zx.client_allocator);
|
||||
const document = zx.client.Document.init(zx.allocator);
|
||||
|
||||
const editor_container = document.querySelector(".cm-content") catch unreachable;
|
||||
|
||||
const c = zx.client.Console.init();
|
||||
c.log(.{editor_container.ref});
|
||||
|
||||
const inner_text: []const u8 = editor_container.ref.getAlloc(zx.Client.js.String, zx.client_allocator, "innerText") catch "NA";
|
||||
const inner_text: []const u8 = editor_container.ref.getAlloc(zx.Client.js.String, zx.allocator, "innerText") catch "NA";
|
||||
std.log.info("Run clicked {s}", .{inner_text});
|
||||
|
||||
// const zx_sourcez = zx.client_allocator.dupeZ(u8, inner_text) catch return;
|
||||
// const ast = zx.Ast.parse(zx.client_allocator, zx_sourcez, .{}) catch return;
|
||||
// const zx_sourcez = zx.allocator.dupeZ(u8, inner_text) catch return;
|
||||
// const ast = zx.Ast.parse(zx.allocator, zx_sourcez, .{}) catch return;
|
||||
// c.log(.{zx.client.js.String(ast.zig_source)});
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ fn reset(_: zx.client.Event) void {
|
||||
}
|
||||
|
||||
fn fetch(url: []const u8) void {
|
||||
_ = zx.fetch(.noop, zx.client_allocator, url, .{}) catch {};
|
||||
_ = zx.fetch(.noop, zx.allocator, url, .{}) catch {};
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
|
||||
@ -14,7 +14,7 @@ const StateContext = CoreEvent.StateContext;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const platform = zx.platform;
|
||||
const client_allocator = zx.client_allocator;
|
||||
const client_allocator = zx.allocator;
|
||||
|
||||
/// Context passed to proxy middleware functions.
|
||||
pub const ProxyContext = struct {
|
||||
@ -50,7 +50,6 @@ pub const ProxyContext = struct {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ----- ComponentCtx ----- //
|
||||
const BindSignMsg =
|
||||
\\
|
||||
|
||||
@ -112,7 +112,6 @@ pub const Socket = routing.Socket;
|
||||
pub const fetch = Fetch.fetch;
|
||||
|
||||
// --- Values --- //
|
||||
pub const client_allocator = if (builtin.cpu.arch == .wasm32) std.heap.wasm_allocator else std.heap.page_allocator;
|
||||
pub const platform: Platform = plfm.platform;
|
||||
pub const std_options: std.Options = opts.std_options;
|
||||
|
||||
|
||||
@ -192,7 +192,7 @@ fn mainClient() callconv(.c) void {
|
||||
clnt.renderAll();
|
||||
}
|
||||
|
||||
var clnt = init(zx.client_allocator, .{});
|
||||
var clnt = init(zx.allocator, .{});
|
||||
const kv_wasm = @import("../server/wasm/kv.zig");
|
||||
pub fn run() !void {
|
||||
// kv_wasm.use();
|
||||
@ -526,7 +526,7 @@ pub fn logFn(
|
||||
.debug => 3,
|
||||
};
|
||||
const prefix = if (scope == .default) "" else "(" ++ @tagName(scope) ++ ") ";
|
||||
const msg = std.fmt.allocPrint(zx.client_allocator, prefix ++ format, args) catch return;
|
||||
defer zx.client_allocator.free(msg);
|
||||
const msg = std.fmt.allocPrint(zx.allocator, prefix ++ format, args) catch return;
|
||||
defer zx.allocator.free(msg);
|
||||
@import("window/extern.zig")._log(level, msg.ptr, msg.len);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ const js = zx.client.js;
|
||||
const is_wasm = zx.platform.role == .client;
|
||||
|
||||
fn getGlobalAllocator() std.mem.Allocator {
|
||||
return zx.client_allocator;
|
||||
return zx.allocator;
|
||||
}
|
||||
|
||||
const ComponentSubKey = struct {
|
||||
|
||||
@ -150,12 +150,12 @@ fn onFormActionResponse(
|
||||
_: ?@import("../core/Fetch.zig").FetchError,
|
||||
) void {
|
||||
const cb_ctx: *FormActionCallbackCtx = @ptrCast(@alignCast(ctx_ptr));
|
||||
defer zx.client_allocator.destroy(cb_ctx);
|
||||
defer zx.allocator.destroy(cb_ctx);
|
||||
|
||||
const resp = response orelse return;
|
||||
if (resp._body.len == 0) return;
|
||||
|
||||
const states = zx.util.zxon.parse([]const []const u8, zx.client_allocator, resp._body, .{}) catch return;
|
||||
const states = zx.util.zxon.parse([]const []const u8, zx.allocator, resp._body, .{}) catch return;
|
||||
for (states, 0..) |state_json, i| {
|
||||
if (i >= cb_ctx.bound_states.len) break;
|
||||
const bs = cb_ctx.bound_states[i];
|
||||
@ -176,7 +176,7 @@ fn formActionCallback(ctx: *anyopaque, event: zx.client.Event) void {
|
||||
}
|
||||
|
||||
// Stateful: serialise bound-state values → JSON array → __$states field.
|
||||
const alloc = zx.client_allocator;
|
||||
const alloc = zx.allocator;
|
||||
var states_list = std.ArrayList([]const u8).empty;
|
||||
for (form_ctx.bound_states) |bs| {
|
||||
states_list.append(alloc, bs.getJson(alloc, bs.state_ptr)) catch {};
|
||||
|
||||
@ -291,7 +291,7 @@ pub const CacheScope = struct {
|
||||
value: ValueType,
|
||||
};
|
||||
|
||||
var writer = std.Io.Writer.Allocating.init(zx.client_allocator);
|
||||
var writer = std.Io.Writer.Allocating.init(zx.allocator);
|
||||
defer writer.deinit();
|
||||
|
||||
try zx.util.zxon.serialize(TypedValue{
|
||||
|
||||
@ -7,7 +7,7 @@ const is_wasm = zx.platform.role == .client;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
fn getGlobalAllocator() std.mem.Allocator {
|
||||
return zx.client_allocator;
|
||||
return zx.allocator;
|
||||
}
|
||||
|
||||
pub const Bound = struct {
|
||||
@ -135,12 +135,12 @@ pub fn action(comptime func: anytype) Self {
|
||||
func(ctx.data(arg_type));
|
||||
}
|
||||
};
|
||||
return .{
|
||||
.callback = &actionHandler,
|
||||
.context = @as(*anyopaque, @ptrFromInt(1)),
|
||||
.action_fn = &DirectTyped.w,
|
||||
.may_suspend = false,
|
||||
};
|
||||
return .{
|
||||
.callback = &actionHandler,
|
||||
.context = @as(*anyopaque, @ptrFromInt(1)),
|
||||
.action_fn = &DirectTyped.w,
|
||||
.may_suspend = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
return wrap(func);
|
||||
|
||||
@ -1,28 +1,9 @@
|
||||
//! Common types for the app module.
|
||||
//! These types are backend-independent and can be used with any HTTP server.
|
||||
//!
|
||||
//! This module re-exports types from `std.http` where available for consistency
|
||||
//! with Zig's standard library.
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
// --- HTTP Header (from std.http) --- //
|
||||
|
||||
/// HTTP header name/value pair - re-exported from std.http.Header for consistency.
|
||||
///
|
||||
/// Fields:
|
||||
/// - `name`: The header name (e.g., "Content-Type", "Authorization")
|
||||
/// - `value`: The header value
|
||||
///
|
||||
/// **Zig Note:** This uses `name` (as per RFC 7230) rather than `key`.
|
||||
/// HTTP header name/value pair
|
||||
pub const Header = std.http.Header;
|
||||
|
||||
/// Alias for backward compatibility.
|
||||
/// @deprecated Use `Header` instead.
|
||||
pub const Entry = Header;
|
||||
|
||||
/// HTTP header iterator for parsing raw header bytes.
|
||||
/// Re-exported from std.http.HeaderIterator for convenience.
|
||||
///
|
||||
/// Useful for parsing HTTP headers from raw bytes. Initializes with `init(bytes)`
|
||||
/// and iterates via `next()` returning `?Header`.
|
||||
@ -51,26 +32,14 @@ pub const MultiFormEntry = struct {
|
||||
///
|
||||
/// **Note:** Unlike some HTTP libraries, std.http.Method does not have an "OTHER"
|
||||
/// variant for unknown methods. All standard HTTP methods are supported.
|
||||
/// TODO: move to using own custom Method type that includes an "OTHER" variant for non-standard methods.
|
||||
pub const Method = std.http.Method;
|
||||
|
||||
// --- HTTP Version (from std.http) --- //
|
||||
|
||||
/// HTTP protocol versions - re-exported from std.http.Version for convenience.
|
||||
///
|
||||
/// Values:
|
||||
/// - `@"HTTP/1.0"`: HTTP/1.0 protocol
|
||||
/// - `@"HTTP/1.1"`: HTTP/1.1 protocol
|
||||
/// HTTP protocol versions
|
||||
pub const Version = std.http.Version;
|
||||
|
||||
/// Alias for backward compatibility.
|
||||
/// @deprecated Use `Version` instead.
|
||||
pub const Protocol = Version;
|
||||
|
||||
// --- Cookie Types --- //
|
||||
|
||||
/// Cookie accessor - parses cookies from the Cookie header.
|
||||
///
|
||||
/// **Zig Note:** This is an extension type not present in the web standard.
|
||||
/// In browsers, cookies are accessed via `document.cookie`.
|
||||
pub const Cookies = struct {
|
||||
header_value: []const u8,
|
||||
@ -163,10 +132,8 @@ pub fn statusCodeToText(code: u16) []const u8 {
|
||||
|
||||
/// Common MIME content types.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
||||
/// MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
||||
///
|
||||
/// **Zig Note:** The standard library does not provide a ContentType enum.
|
||||
/// This enum uses the actual MIME type string as the tag name for convenience.
|
||||
pub const ContentType = enum {
|
||||
// Application types
|
||||
@"application/gzip",
|
||||
@ -226,19 +193,11 @@ pub const ContentType = enum {
|
||||
}
|
||||
};
|
||||
|
||||
// --- Re-exports from std.http for convenience --- //
|
||||
|
||||
/// HTTP content encoding - re-exported from std.http.ContentEncoding.
|
||||
///
|
||||
/// Values: zstd, gzip, deflate, compress, identity
|
||||
pub const ContentEncoding = std.http.ContentEncoding;
|
||||
|
||||
/// HTTP transfer encoding - re-exported from std.http.TransferEncoding.
|
||||
///
|
||||
/// Values: chunked, none
|
||||
pub const TransferEncoding = std.http.TransferEncoding;
|
||||
|
||||
/// HTTP connection type - re-exported from std.http.Connection.
|
||||
///
|
||||
/// Values: keep_alive, close
|
||||
pub const Connection = std.http.Connection;
|
||||
|
||||
@ -117,7 +117,7 @@ fn putTyped(ns: []const u8, key: []const u8, value: anytype, opts: PutOptions) !
|
||||
value: ValueType,
|
||||
};
|
||||
|
||||
var writer = std.Io.Writer.Allocating.init(zx.client_allocator);
|
||||
var writer = std.Io.Writer.Allocating.init(zx.allocator);
|
||||
defer writer.deinit();
|
||||
|
||||
try zx.util.zxon.serialize(TypedValue{
|
||||
|
||||
@ -29,7 +29,7 @@ fn reset(_: zx.client.Event) void {
|
||||
}
|
||||
|
||||
fn fetch(url: []const u8) void {
|
||||
_ = zx.fetch(.noop, zx.client_allocator, url, .{}) catch {};
|
||||
_ = zx.fetch(.noop, zx.allocator, url, .{}) catch {};
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user