Giter VIP home page Giter VIP logo

Comments (6)

atjn avatar atjn commented on May 26, 2024 1

the issue is we CANNOT do ES6+ module export because you can't try/catch and without it breaks old browsers.

@amark what old browsers are you trying to support? To not have ES6 support, you would need to be using a 5+ year old browser. That is so old, it would be trivial to hack. According to caniuse, ~98.5%* of all network traffic supports ES6, and when you factor in that GUN already uses some methods that are not supported in old browsers, it is likely only a very small set of browsers that would see new breakage.

If any developer has a need to support these old browsers, it is relatively simple to install Babel and transpile it to ancient JS. You could even do the transpiling in this repo and provide a simple code example showing how to conditionally load the transpiled vs new version of GUN.

*: adjusting for known issues with caniuse's data

from gun.

eternal-turtles avatar eternal-turtles commented on May 26, 2024 1

We found that adding the following at the top of the worker script is sufficient for importing gun/gun and gun/sea: self.window = self;. I haven't had time yet to actually test doing anything with gun within a worker, but I'll be on the lookout for the WebRTC issue - thanks @imizaac

from gun.

amark avatar amark commented on May 26, 2024

@eternal-turtles @bmatusiak

https://github.com/amark/gun/blob/master/gun.js#L544

should only do if window exists, idk why its doing it without.

but maybe module also doesn't exist, so it is never exported & never globalized?

the issue is we CANNOT do ES6+ module export because you can't try/catch and without it breaks old browsers.

so maybe we can do something like window||self in a safe way?

from gun.

bmatusiak avatar bmatusiak commented on May 26, 2024

I think the global is called WorkerGlobalScope or something stupid

from gun.

eternal-turtles avatar eternal-turtles commented on May 26, 2024

@amark Yes, if the first line is removed ( const window = {};), then the gun.js import won't fail, there's just no way I've found to actually access GUN. The window || self fallback would work I think, but it looks like globalThis may be more appropriate depending on browser support (hadn't heard about this before, thanks @bmatusiak) - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

from gun.

0awful avatar 0awful commented on May 26, 2024

@atjn There's also a question of if it would be better to use polyfills to regain the support of older browsers.

On the topic of the thread. @eternal-turtles If you're attempting to use GUN within a web worker you may run into additional problems. AFAIK you cannot open a webRTC connection within a web worker and I believe GUNDB does require webrtc. Do watch my words though because in the link I call out it is mentioned that you can transfer an existing webrtc connection to a web worker. Will that work with GUN? Who knows! @amark might have an answer but experimentation may give us all more information.

from gun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.