Skip to content
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

[micro-dash] throttle's performance.now() not available in React Native #31

Open
benallfree opened this issue Mar 3, 2021 · 6 comments

Comments

@benallfree
Copy link

Just FYI, I think +new Date() would be more compatible.

@ersimont
Copy link
Member

ersimont commented Mar 5, 2021

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?

@benallfree
Copy link
Author

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.

@ersimont
Copy link
Member

ersimont commented Mar 7, 2021

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. :)

@ersimont ersimont changed the title throttle's performance.now() not available in React Native [micro-dash] throttle's performance.now() not available in React Native Mar 7, 2021
@benallfree
Copy link
Author

Interesting thought on the polyfill, I will see if that works. Maybe I can do global.performance = { now: ()=>+new Date() } or something.

@ersimont
Copy link
Member

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? :)

@benallfree
Copy link
Author

I’d suggest it’s worth revisiting. Unfortunately I’ve moved on for the time being, but the issue is still valid imho :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants