-
|
Ahoy there coming from React I'm really excited to get started with Solid and make some cool stuff. As the title suggests im curious what the best practice is for accessing a class property and rendering updates to property changes. For example I have... import {onCleanup} from "solid-js";
export default function App() {
const ctx = new AudioContext()
function onWindowClick() {
if(ctx.state === 'suspended') {
ctx.resume();
}
}
window.addEventListener('click', onWindowClick);
onCleanup(() => {
window.removeEventListener('click', onWindowClick);
});
return <p>{ctx.state}</p>
}And I'm trying to render the new |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
If you want it to update in the view or drive Solid's view you do need it represented in the reactive system. This is no different than any other frontend framework(except maybe Angular zone). React won't update for things not in I believe AudioContext has an |
Beta Was this translation helpful? Give feedback.
If you want it to update in the view or drive Solid's view you do need it represented in the reactive system. This is no different than any other frontend framework(except maybe Angular zone). React won't update for things not in
state. RxJS would expect you to drive this from an event, etc... Since AudioContext is not reactive your only recourse is to have it drive reactive values. If it is something you control that's easy enough. Otherwise you will need to tap into events when it is changed outside of your code and synchronize accordingly.I believe AudioContext has an
onstatechangeevent. But it looks like you'd need to compare the current and previous state yourself given the way it …