-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
WIP add TypeScript #7
base: master
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
// Use TypeScript only for type checking. | ||
"noEmit": true, | ||
|
||
// Run TypeScript on JS files. | ||
"checkJs": true, | ||
"allowJs": true, | ||
|
||
// Strict settings to enforce the most type-safe code. | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true | ||
}, | ||
"include": ["./wasmaudioworklet/**/*"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ import { initVisualizer } from './visualizer/80sgrid.js'; | |
import { initEditor } from './editorcontroller.js'; | ||
|
||
customElements.define('app-javascriptmusic', | ||
class extends HTMLElement { | ||
class JavaScriptMusic extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
const shadowRoot = this.attachShadow({mode: 'open'}); | ||
this.shadowRoot = this.attachShadow({mode: 'open'}); | ||
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.
|
||
this.init(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,21 @@ | |
*/ | ||
|
||
if(typeof AudioContext !== 'function') { | ||
window.AudioContext = window.webkitAudioContext; | ||
/** @type {any} */ | ||
const win = window | ||
window.AudioContext = win.webkitAudioContext; | ||
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. I used |
||
} | ||
|
||
if(typeof AudioWorkletNode !== 'function') { | ||
console.log('No audioworklet support - using polyfill'); | ||
window.AudioWorkletNode = function(context, processorName) { | ||
|
||
window.AudioWorkletNode = /** @type {AudioWorkletNode} */(AudioWorkletNodePolyfill) | ||
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. This syntax is a type cast. The parentheses are required here. |
||
|
||
/** | ||
* @param {any} context | ||
* @param {any} processorName | ||
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. As a quick escape hatch, just give things type I'm just getting it set up, I'll update the types a little later... |
||
*/ | ||
function AudioWorkletNodePolyfill(context, processorName) { | ||
let connected = false; | ||
return { | ||
context: context, | ||
|
@@ -114,3 +123,6 @@ if(typeof AudioWorkletNode !== 'function') { | |
window.audioWorkletProcessors[name] = new processorClass(); | ||
} | ||
} | ||
|
||
// For TypeScript to recognize the file as a "module". | ||
export {} | ||
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. Due to legacy TypeScript functionality from before ES Modules were a thing, any file without an |
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.
Giving the class a name improves the intellisense output in editors.