facebook / facebook/relay

How to create environment factory

Open
#4,589 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

When route init, I will call `loadEntryPoint`. But because this function is not inside react component, so I can not get the environment.

```js
const initGeminiRouting = () => {
const url = "/home" // suppose default is home

// create home tab
init("Home")
}

const WorkAppTabSet = [
{
id: "home",
tabIconName: "HOME",
href: "/",
defaultEntityKey: "feed/newsfeed",
title: fbt("Home", "Home"),
trackingNodeType: 401,
badgeRenderer: WorkGalahadAppTabKeyUpdatesBadgeRenderer,
channelEntryPoint: WorkGalahadHomeTabContainer_entrypoint,
},
{
id: "notifications",
title: fbt("Notifications", "Notifications"),
tabIconName: "NOTIFICATIONS",
trackingNodeType: 402,
href: "/notifications",
defaultEntityKey: "notifications",
channelEntryPoint: undefined,
badgeRenderer: WorkGalahadAppTabNotificationsBadgeRenderer,
channelEntryPoint: WorkGalahadNotificationsTabContainer_entrypoint,
},
{
id: "chats",
title: fbt("Chat", "Chat"),
tabIconName: "CHAT",
trackingNodeType: 403,
href: "/chats",
defaultEntityKey: "chats",
channelEntryPoint: undefined,
badgeRenderer: WorkGalahadAppTabChatBadgeRenderer,
channelEntryPoint: WorkGalahadChatTabContainer_entrypoint,
},
{
id: "knowledge_library",
title: "Knowledge Library",
tabIconName: "KNOWLEDGE_LIBRARY",
trackingNodeType: 478,
href: "/work/knowledge",
defaultEntityKey: "knowledge",
channelEntryPoint: undefined,
},
];

let preloadTriggerID = null;
const init = (id, entry) => {
preloadTriggerID = id;

if (preloadTriggerID === "profile") {
// TODO
}

const tab = WorkAppTabSet.find((tab) => {
return tab.id === preloadTriggerID;
});

if (!tab ? undefined : tab.channelEntryPoint) {
preloadedEntryPointsMap = loadEntryPoint(
ENVIRONMENT // ????,
tab.channelEntryPoint,
{}
);
} else if (entry) {
preloadedEntryPointsMap = loadEntryPoint(
ENVIRONMENT // ????,
entry,
{}
);
} else {
throw unrecoverableViolation(
"couldnt find an entrypoint for current channel",
"work_comet_core"
);
}
};
```

My question is: How can I create something like environment factory ?

Contributor guide

Open the contributing guide

Research direction

Start by tracing the `loadEntryPoint` calls in the issue and locating how `ENVIRONMENT` is supplied when entry points are loaded from React components. No repository file or test is named, so first identify the supported environment-creation path in Relay. Done means the documented approach clearly explains how to obtain or create the environment outside a component.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
developer-experience, frontend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.