Open benallfree opened 3 years ago
Interesting. I haven't used react native. What is its philosophy on providing things that a JS developer is used to? Matching some specs? Some specific browser or node environments? (Almost) all the browsers seem to have it: https://caniuse.com/?search=performance.now
Is there a resource to see what react native provides? Or does it depend on the device/environment?
That's a really good question. Probably anything EcmaScript (https://262.ecma-international.org/5.1/) is safe. https://reactnative.dev/docs/javascript-environment
Definitely nothing DOM. Some window
is available, like addEventListener
, but I can't find a solid reference.
Some environments such as Electron do extend to expose Node-like modules such as fs
and path
, and RN can achieve remarkable parity with NodeJS via https://github.com/tradle/rn-nodeify.
In any case, performance ? performance.now : +new Date()
will probably fix this particular case.
I tried turning off "dom" types to see how much of microdash would break. Only throttle and debounce! However, it shows that setTimeout
and clearTimeout
are also coming from the DOM. I suppose react native must also support that, but that makes it feel more arbitrary.
The other way I could see going is to say "micro-dash assumes a DOM", and expect polyfills when running in other environments. Still thinking about this. Philosophically. :)
Interesting thought on the polyfill, I will see if that works. Maybe I can do global.performance = { now: ()=>+new Date() }
or something.
It has been a while, but I'm just looking back through issues. Any luck with the polyfill? Should I close this issue out or revisit? :)
I’d suggest it’s worth revisiting. Unfortunately I’ve moved on for the time being, but the issue is still valid imho :)
Just FYI, I think
+new Date()
would be more compatible.