Tone.js
Tone.js copied to clipboard
import * as Tone from 'tone' produces warnings due to module side effects
In looking at https://github.com/Tonejs/Tone.js/blob/dev/Tone/index.ts#L33, I see this line:
export const Transport = getContext().transport;
If this executes before Tone.start(), it will produce the The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. warning. Same note with Master, Destination, Listener and Draw.
Yet, there is no way to import without executing these inline getContext() calls.
Everything seems to work anyway, but simply importing Tone produces warnings.
I see getters for most of these, is there a reason those aren't required?
import { getTransport } from 'tone'
That behavior is in there for backwards compatibility since the singleton Transport object has been like that since the beginning. The intention has always been to move to getTransport(), but the question of when is a little tricky since it would likely break many projects, so it would require a good deal of messaging and some warnings before that happens. But it's also tricky to detect when people use the singleton Transport vs the singleton getter (getTransport()).
What about starting a new branch with side effects and the singleton removed?
Maybe npm i tone.js@pure or something?
Would it be enough to remove the inline Transport call on https://github.com/Tonejs/Tone.js/blob/dev/Tone/index.ts#L33 and release a new major version of Tone.js?