It’s actually quite safe provided you follow the documentation and model the mutation in a type-safe way:
- The (Reason built-in)
ref(something)
type tells you that there is mutation going on
- The
option(something)
type tells you that something may or may not be there, so you need to check for both cases
The safety comes from modelling even side-effectful code using the correct types, and restricting mutation to as small a scope as possible. These are fundamental techniques in FP. Admittedly, Elm promises a bit more safety by restricting what you can do, but there’s always a tradeoff.
Right, so normally I’d say to use the bs-webapi bindings, but looks like there’s none for audio
… yet. I’d recommend writing a play
binding yourself against an abstract audioElement
type and just casting the ref’s value (beep
) to audioElement
to legally be able to call the binding.