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

feat: WeakMap when environments are referenced #3014

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/relay-experimental/FragmentResource.js
Expand Up @@ -437,7 +437,7 @@ function createFragmentResource(environment: IEnvironment): FragmentResource {
return new FragmentResourceImpl(environment);
}

const dataResources: Map<IEnvironment, FragmentResource> = new Map();
const dataResources: WeakMap<IEnvironment, FragmentResource> = new WeakMap();
maraisr marked this conversation as resolved.
Show resolved Hide resolved
function getFragmentResourceForEnvironment(
environment: IEnvironment,
): FragmentResourceImpl {
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-experimental/QueryResource.js
Expand Up @@ -527,7 +527,7 @@ function createQueryResource(environment: IEnvironment): QueryResource {
return new QueryResourceImpl(environment);
}

const dataResources: Map<IEnvironment, QueryResource> = new Map();
const dataResources: WeakMap<IEnvironment, QueryResource> = new WeakMap();
maraisr marked this conversation as resolved.
Show resolved Hide resolved
function getQueryResourceForEnvironment(
environment: IEnvironment,
): QueryResourceImpl {
Expand Down
6 changes: 5 additions & 1 deletion packages/relay-runtime/query/fetchQueryInternal.js
Expand Up @@ -34,7 +34,11 @@ type RequestCacheEntry = {|
+subscription: Subscription,
|};

const requestCachesByEnvironment = new Map();
const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';

const requestCachesByEnvironment = WEAKMAP_SUPPORTED
? new WeakMap()
: new Map();

/**
* Fetches the given query and variables on the provided environment,
Expand Down