Closed jsantell closed 6 years ago
I see what you're getting at here. Doesn't seem like a terrible idea to me, but I would definitely want to make the threshold to use it just inconvenient enough that you don't just flip the switch without thinking about it. In my ideal world that might look like being required to explicitly include a separate file in order to access the PRIVATE symbol, but I'm not sure if that actually works with the way we're packaging the polyfill.
If using the polyfill (like in A-Frame's example, if they were to use WebXR), generally you're still using the built artifact via:
import WebXRPolyfill from 'webxr-polyfill'
with no custom rules, and general spec-compliant polyfill results.
Accessing the private values requires opting in via pulling in individual components, which generally requires more overhead in a build system, and only really necessary for someone extending or customization the polyfill:
import XRSession, { PRIVATE } from 'webxr-polyfill/src/api/XRSession.js';
In my mind, once reaching into individual components, the warranty has been broken, so to speak :)
The original idea for the internals being hidden behind an unexposed Symbol was such that developers don't rely on any Polyfill-specific implementation during development, which would cause a breakage when using native WebXR on a supported platform. Admittedly, it's rather conservative and has been annoying at times while working on the WebVRDevice, as the API internals are not accessible from there.
When extending the polyfill to provide custom behavior, one (AFAIK) can extend the PolyfilledXRDevice and let the
./src/api/*
components handle all the XR mechanisms, where you'll run into some issues with not being able to access the internals in some areas. Exposing the private symbol from the modules is an explicit opt-in for those extending the polyfill, and still maintain the benefit of the values not being exposed to web content.Usage:
Probably more beneficial for introspection rather than modification, but of course YMMV. I believe both @mprafson and @TrevorFSmith are using the polyfill in this regard -- hope it helps!