Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @ts-ignore
.subscribe(({ data }) => observer.onNext({ data }))
);
};
const network = Network.create(fetchQuery, setupSubscription);
const source = new RecordSource();
const store = new Store(source);
const env = new Environment({
network,
store
});
commitLocalUpdate(env, proxyStore => {
const fieldKey = "settings";
const __typename = "Settings";
const dataID = `client:${__typename}`;
const record = proxyStore.create(dataID, __typename);
record.setValue("light", "theme");
// avoid garbage collection
env.retain({
dataID,
variables: {},
// @ts-ignore
node: { selections: [] }
});
export default async function initLocalState(
environment: Environment,
context: CoralContext
) {
const config = await getExternalConfig(context.pym);
await initLocalBaseState(
environment,
context,
config ? config.accessToken : undefined
);
commitLocalUpdate(environment, s => {
const root = s.getRoot();
const localRecord = root.getLinkedRecord("local")!;
// Parse query params
const query = parseQuery(location.search);
if (query.storyID) {
localRecord.setValue(query.storyID, "storyID");
}
if (query.storyURL) {
localRecord.setValue(query.storyURL, "storyURL");
}
if (query.commentID) {
localRecord.setValue(query.commentID, "commentID");
installRelayDevTools()
}
const network = Network.create(
process.env.NODE_ENV === 'development' ? RelayNetworkLogger.wrapFetch(cacheHandler) : cacheHandler
)
const source = new RecordSource()
const store = new Store(source)
const env = new Environment({
network,
store,
})
commitLocalUpdate(env, proxyStore => {
const fieldKey = 'settings'
const __typename = 'Settings'
const dataID = `client:${__typename}`
const record = proxyStore.create(dataID, __typename)
const darkTheme = localStorage.getItem(yottaDarkTheme) === 'true'
record.setValue(darkTheme, 'darkTheme')
env.retain({
dataID,
variables: {},
// @ts-ignore
node: { selections: [] },
})
network = Network.create(
wrapFetchWithLogger(createFetch({ schema }), {
logResult: params.network.logNetwork,
muteErrors: params.network.muteNetworkErrors,
}),
params.network.subscriptionHandler
? (createSubscribe(params.network.subscriptionHandler) as any)
: undefined
);
}
const environment = new Environment({
network,
store: new Store(params.source || new RecordSource()),
});
if (params.initLocalState !== false) {
commitLocalUpdate(environment, sourceProxy => {
const root = sourceProxy.getRoot();
const localRecord = createAndRetain(
environment,
sourceProxy,
LOCAL_ID,
LOCAL_TYPE
);
root.setLinkedRecord(localRecord, "local");
if (typeof params.initLocalState === "function") {
params.initLocalState(localRecord, sourceProxy, environment);
}
});
}
return environment;
}
export async function commit(
environment: Environment,
input: SetAuthPopupStateInput
) {
return commitLocalUpdate(environment, store => {
const record = store.get(AUTH_POPUP_ID)!;
if (input.open !== undefined) {
record.setValue(input.open, "open");
}
if (input.focus !== undefined) {
record.setValue(input.focus, "focus");
}
if (input.href !== undefined) {
record.setValue(input.href, "href");
}
});
}
export async function commit(
environment: Environment,
input: SetStoryClosedInput
) {
return commitLocalUpdate(environment, store => {
const record = store.get(input.storyID)!;
record.setValue(input.isClosed, "isClosed");
});
}
export async function commit(
environment: Environment,
input: SetActiveTabInput,
{ eventEmitter }: Pick
) {
return commitLocalUpdate(environment, store => {
const record = store.get(LOCAL_ID)!;
if (record.getValue("activeTab") !== input.tab) {
SetMainTabEvent.emit(eventEmitter, { tab: input.tab });
record.setValue(input.tab, "activeTab");
}
});
}
store = (storeUpdater: StoreUpdater) => {
commitLocalUpdate(this.props.environment, storeUpdater);
};
async (
environment: Environment,
input: SetRedirectPathInput,
{ localStorage }: CoralContext
) => {
if (!input.path) {
await localStorage.removeItem(REDIRECT_PATH_KEY);
} else {
await localStorage.setItem(REDIRECT_PATH_KEY, input.path);
}
return commitLocalUpdate(environment, store => {
const record = store.get(LOCAL_ID)!;
record.setValue(input.path, "redirectPath");
});
}
);
(update: LocalUpdater) => {
commitLocalUpdate(relayEnvironment, store => {
const record = store.get(LOCAL_ID)!;
if (isAdvancedUpdater(update)) {
update(record);
} else {
applySimplified(record, fragment.selections[0].selections, update);
}
});
return;
},
[relayEnvironment, fragment]