Skip to content

Use the IIFE source trick instead of hard-coding function sources#5

Draft
atesgoral wants to merge 2 commits into
keithwhor:mainfrom
atesgoral:iife
Draft

Use the IIFE source trick instead of hard-coding function sources#5
atesgoral wants to merge 2 commits into
keithwhor:mainfrom
atesgoral:iife

Conversation

@atesgoral
Copy link
Copy Markdown

@atesgoral atesgoral commented Apr 16, 2025

This is a quality of life improvement that also reduces the size of the minified bundle by ~25%.

Please view white-space-agnostic diff: https://github.com/keithwhor/wavtools/pull/5/files?diff=split&w=1

Hard-coding function sources as strings:

  1. No syntax highlighting, formatting, linting, etc.
  2. Have to escape backticks

This PR moves worklet code into worklet functions that will get immediately executed (IIFE) within the workers.

Before:

➜  wavtools git:(iife) ✗ ls -al script/wavtools.min.js 
-rw-r--r--  1 atesgoral  staff  21750 Apr 16 00:43 script/wavtools.min.js

After:

➜  wavtools git:(iife) ✗ ls -al script/wavtools.min.js
-rw-r--r--@ 1 atesgoral  staff  16636 Apr 16 00:46 script/wavtools.min.js

Also, package-lock.json is stuck on an older package.json version. The first commit updates that.

Also updating Prettier rules to enable trailing commas, which seems to be the prevalent convention in this repo.

@keithwhor
Copy link
Copy Markdown
Owner

keithwhor commented Apr 16, 2025

Thanks for styling update!

Biggest concern I have here is that, IIRC, in certain WebPack / TS environments and configs, errors will get thrown for Audio Worklets (as they're not available in browser context). The code will also get minified; breaking the functionality of the worklet. The fix is the hardcoded string (or to host the worklet separately as a vendor public file). Can you verify this compiles as expected in e.g. create-react-app / Next.js?

If it does I'm cool with it -- much prefer the syntax highlighting, etc. My solution here was only a hack around specific environment setups.

Comment thread lib/worklets/audio_processor.js Outdated
@atesgoral
Copy link
Copy Markdown
Author

@keithwhor Will check! TBH, I YOLO made these changes without any testing. Was at the brink of throwing in some test config for some rudimentary smoke tests. Or perhaps an examples/kitchen-sink.html file.

@atesgoral atesgoral marked this pull request as draft April 16, 2025 05:54
@atesgoral
Copy link
Copy Markdown
Author

atesgoral commented Apr 16, 2025

Moved styling stuff to #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants