isomorphic-form-data icon indicating copy to clipboard operation
isomorphic-form-data copied to clipboard

Use "self" instead of "window"

Open jorrete opened this issue 4 years ago • 7 comments

Could be possible to use self instead of window?

module.exports = self.FormData

I'm trying to instantiate Swagger in a webworker, and it is complaining because window doesn't exist.

jorrete avatar Feb 20 '21 10:02 jorrete

There is been quite a motion around it, please check commit history :)

Maybe it’s time to create number of wrappers for different use cases. 🤔

cc @DylanPiercey

alexindigo avatar Feb 20 '21 16:02 alexindigo

Sorry, I had in mind different file – https://github.com/form-data/form-data/commits/master/lib/browser.js

@DylanPiercey I think we can copy what we have there.

alexindigo avatar Feb 21 '21 03:02 alexindigo

@alexindigo yeah that should work

DylanPiercey avatar Feb 21 '21 04:02 DylanPiercey

@alexindigo given the goal of this module is to expose FormData globally, should we make a breaking change / major release and no longer export FormData? It seems like really the browser file for this module should just be empty, since presumably FormData is already global in the browser, even in a worker.

Alternatively, again since we are assuming there is already the global, could we not just change this to module.exports = FormData?

DylanPiercey avatar Feb 21 '21 16:02 DylanPiercey

I'm also having the exact same issue, Can't use swagger-js in web worker because of this.

image

I'm also +1 to @DylanPiercey idea exporting directly module.exports = FormData rather than adding to the global window object.

tmkasun avatar Apr 01 '21 04:04 tmkasun

What about using already standardized globalThis? I'll issue a PR if agreed that this is path forward.

char0n avatar Apr 01 '21 14:04 char0n

I've issued a PR: https://github.com/form-data/isomorphic-form-data/pull/6 for using globalThis object. It's a breaking change but will work in all major browsers and latest node.js versions (and that's what we currently need).

char0n avatar Jul 07 '21 10:07 char0n