-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
don't generate unused functions in bindings #138
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,14 @@ export type RandomNumber = number | |
|
||
import { | ||
invoke as TAURI_INVOKE, | ||
Channel as TAURI_CHANNEL, | ||
} from "@tauri-apps/api/core"; | ||
|
||
|
||
export type Result<T, E> = | ||
| { status: "ok"; data: T } | ||
| { status: "error"; error: E }; | ||
|
||
|
||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; | ||
|
||
|
@@ -46,15 +52,11 @@ type __EventObj__<T> = { | |
once: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
emit: T extends null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this change? It also differs from the JS Doc alternative so they will need to match for this to be merged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be honest i don't know when/how this changed. i will undo the change. |
||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
emit: null extends T | ||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
}; | ||
|
||
export type Result<T, E> = | ||
| { status: "ok"; data: T } | ||
| { status: "error"; error: E }; | ||
|
||
function __makeEvents__<T extends Record<string, any>>( | ||
mappings: Record<keyof T, string>, | ||
) { | ||
|
@@ -68,7 +70,7 @@ function __makeEvents__<T extends Record<string, any>>( | |
get: (_, event) => { | ||
const name = mappings[event as keyof T]; | ||
|
||
return new Proxy((() => {}) as any, { | ||
return new Proxy((() => { }) as any, { | ||
apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
listen: (arg: any) => window.listen(name, arg), | ||
once: (arg: any) => window.once(name, arg), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,9 @@ | ||
import { | ||
invoke as TAURI_INVOKE, | ||
Channel as TAURI_CHANNEL, | ||
} from "@tauri-apps/api/core"; | ||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
|
||
/** @typedef {typeof import("@tauri-apps/api/window").WebviewWindowHandle} __WebviewWindowHandle__ */ | ||
|
||
/** | ||
* @template T | ||
* @typedef {{ | ||
* listen: ( | ||
* cb: TAURI_API_EVENT.EventCallback<T> | ||
* ) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
* once: ( | ||
* cb: TAURI_API_EVENT.EventCallback<T> | ||
* ) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
* emit: T extends null | ||
* ? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
* : (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
* }} __EventObj__<T> | ||
*/ | ||
|
||
/** | ||
* @template T,E | ||
* @typedef { { status: "ok", data: T } | { status: "error", error: E } } Result | ||
*/ | ||
|
||
/** | ||
* @template {Record<string, any>} T | ||
* @param {Record<keyof T, string>} mappings | ||
* @returns {{ | ||
* [K in keyof T]: __EventObj__<T[K]> & { | ||
* (handle: __WebviewWindowHandle__): __EventObj__<T[K]>; | ||
* }; | ||
* }} | ||
*/ | ||
function __makeEvents__(mappings) { | ||
return new Proxy( | ||
{}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event]; | ||
|
||
new Proxy(() => {}, { | ||
apply: (_, __, [window]) => ({ | ||
listen: (arg) => window.listen(name, arg), | ||
once: (arg) => window.once(name, arg), | ||
emit: (arg) => window.emit(name, arg), | ||
}), | ||
get: (_, command) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
}, | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,9 @@ | ||
import { | ||
invoke as TAURI_INVOKE, | ||
Channel as TAURI_CHANNEL, | ||
} from "@tauri-apps/api/core"; | ||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; | ||
|
||
type __EventObj__<T> = { | ||
listen: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
once: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
emit: null extends T | ||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
}; | ||
|
||
export type Result<T, E> = | ||
| { status: "ok"; data: T } | ||
| { status: "error"; error: E }; | ||
|
||
function __makeEvents__<T extends Record<string, any>>( | ||
mappings: Record<keyof T, string>, | ||
) { | ||
return new Proxy( | ||
{} as unknown as { | ||
[K in keyof T]: __EventObj__<T[K]> & { | ||
(handle: __WebviewWindow__): __EventObj__<T[K]>; | ||
}; | ||
}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event as keyof T]; | ||
|
||
return new Proxy((() => {}) as any, { | ||
apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
listen: (arg: any) => window.listen(name, arg), | ||
once: (arg: any) => window.once(name, arg), | ||
emit: (arg: any) => window.emit(name, arg), | ||
}), | ||
get: (_, command: keyof __EventObj__<any>) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg: any) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg: any) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg: any) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
}, | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
|
||
/** @typedef {typeof import("@tauri-apps/api/window").WebviewWindowHandle} __WebviewWindowHandle__ */ | ||
|
||
/** | ||
* @template T | ||
* @typedef {{ | ||
* listen: ( | ||
* cb: TAURI_API_EVENT.EventCallback<T> | ||
* ) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
* once: ( | ||
* cb: TAURI_API_EVENT.EventCallback<T> | ||
* ) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
* emit: T extends null | ||
* ? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
* : (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
* }} __EventObj__<T> | ||
*/ | ||
|
||
/** | ||
* @template {Record<string, any>} T | ||
* @param {Record<keyof T, string>} mappings | ||
* @returns {{ | ||
* [K in keyof T]: __EventObj__<T[K]> & { | ||
* (handle: __WebviewWindowHandle__): __EventObj__<T[K]>; | ||
* }; | ||
* }} | ||
*/ | ||
function __makeEvents__(mappings) { | ||
return new Proxy( | ||
{}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event]; | ||
|
||
new Proxy(() => { }, { | ||
apply: (_, __, [window]) => ({ | ||
listen: (arg) => window.listen(name, arg), | ||
once: (arg) => window.once(name, arg), | ||
emit: (arg) => window.emit(name, arg), | ||
}), | ||
get: (_, command) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
}, | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; | ||
|
||
type __EventObj__<T> = { | ||
listen: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
once: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
emit: null extends T | ||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
}; | ||
|
||
function __makeEvents__<T extends Record<string, any>>( | ||
mappings: Record<keyof T, string>, | ||
) { | ||
return new Proxy( | ||
{} as unknown as { | ||
[K in keyof T]: __EventObj__<T[K]> & { | ||
(handle: __WebviewWindow__): __EventObj__<T[K]>; | ||
}; | ||
}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event as keyof T]; | ||
|
||
return new Proxy((() => { }) as any, { | ||
apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
listen: (arg: any) => window.listen(name, arg), | ||
once: (arg: any) => window.once(name, arg), | ||
emit: (arg: any) => window.emit(name, arg), | ||
}), | ||
get: (_, command: keyof __EventObj__<any>) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg: any) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg: any) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg: any) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
}, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the changes in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the js.rs file has this use
use specta_typescript::{js_doc, ExportError, Typescript};
So compiling without the specta_typescript dependency fails if only the javascript feature is set.
This is why the dependency is now not optional anymore and the 'dep:..' is not needed.