Comments (6)
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.
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.
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.
I think the global is called WorkerGlobalScope or something stupid
from gun.
@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.
@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)
- [Docs] are really difficult to use! HOT 4
- are there any recipies how to model data structures properly for Gun? HOT 1
- [Doc] user example is wrong? HOT 2
- [Doc] how can one find the root node of a given user? HOT 2
- [Doc] how can one write encrypted data? HOT 2
- [Doc] is the SEA Quickstart example wrong? HOT 3
- [RAD] I'm completely lost... HOT 9
- If you put data in a key with one gun instance, then change that data on another gun instance, the first instance will be unable to read the change HOT 5
- Unable to use Array.push inside once() HOT 1
- [Bug] _ev.off() disables the entire .map() listener, rather than the individual item HOT 1
- Silent Failure on Incorrect Certificate and Delayed put HOT 1
- How to deploy gun server by Docker? HOT 4
- [Question] Netx.js support? HOT 1
- Why is the source code so bad? HOT 2
- Can not access docs HOT 2
- load() issue HOT 2
- Gun integration with express not working HOT 3
- Once dosen't trigger most of the time, when messages are authenticated to an user. HOT 1
- Gun not working with next.js 14.0.4 HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gun.