Skip to content
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
5 changes: 5 additions & 0 deletions .changes/channel-ctor-callback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": minor:feat
---

Allow passing the callback as the parameter of constructor of `Channel` so you can use it like this `new Channel((message) => console.log(message))`
6 changes: 6 additions & 0 deletions .changes/channel-never-cleaned-up.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": minor:bug
"@tauri-apps/api": minor:bug
---

Fix `Channel`'s callback attached to `window` never cleaned up
5 changes: 5 additions & 0 deletions .changes/channel-small-payload-perf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": minor:perf
---

Improve `Channel`'s performance when sending small amount of data (e.g. sending a number)
18 changes: 9 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions crates/tauri/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

Object.defineProperty(window.__TAURI_INTERNALS__, 'transformCallback', {
value: function transformCallback(callback, once) {
var identifier = uid()
var prop = `_${identifier}`
const identifier = uid()
const prop = `_${identifier}`

Object.defineProperty(window, prop, {
value: (result) => {
Expand Down Expand Up @@ -56,15 +56,11 @@
Object.defineProperty(window.__TAURI_INTERNALS__, 'invoke', {
value: function (cmd, payload = {}, options) {
return new Promise(function (resolve, reject) {
const callback = window.__TAURI_INTERNALS__.transformCallback(function (
r
) {
const callback = window.__TAURI_INTERNALS__.transformCallback((r) => {
resolve(r)
delete window[`_${error}`]
}, true)
const error = window.__TAURI_INTERNALS__.transformCallback(function (
e
) {
const error = window.__TAURI_INTERNALS__.transformCallback((e) => {
reject(e)
delete window[`_${callback}`]
}, true)
Expand Down
18 changes: 8 additions & 10 deletions crates/tauri/scripts/process-ipc-message-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

(function (message) {
if (
message instanceof ArrayBuffer ||
ArrayBuffer.isView(message) ||
Array.isArray(message)
message instanceof ArrayBuffer
|| ArrayBuffer.isView(message)
|| Array.isArray(message)
) {
return {
contentType: 'application/octet-stream',
Expand All @@ -27,15 +27,13 @@
return Array.from(val)
} else if (val instanceof ArrayBuffer) {
return Array.from(new Uint8Array(val))
} else if (typeof val === "object" && val !== null && SERIALIZE_TO_IPC_FN in val) {
return val[SERIALIZE_TO_IPC_FN]()
} else if (
val instanceof Object &&
'__TAURI_CHANNEL_MARKER__' in val &&
typeof val.id === 'number'
typeof val === 'object'
&& val !== null
&& SERIALIZE_TO_IPC_FN in val
) {
return `__CHANNEL__:${val.id}`
} else {
return val[SERIALIZE_TO_IPC_FN]()
} else {
return val
}
})
Expand Down
Loading
Loading