-
Notifications
You must be signed in to change notification settings - Fork 9
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: Update InitialContext #184
Conversation
InitialContext will always be available when run in a portal context with at least the name value defined. This now makes `getInitialContext` an indicator to the web developers whether or not their code is being executed inside of a Portal or not without the native team having to provide any initialContext if it is not needed. BREAKING CHANGE This is an API breaking change since InitialContext<T> was initially assumed to always have a value provided if it was present. This is now changed so that we always provide access to the name of the portal to the web code to avoid there being strong coupling to the name.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
export function getInitialContext<T = unknown>(): InitialContext<T> | undefined { | ||
return (window as any).portalInitialContext as { name: string, value: T; }; | ||
return (window as any).portalInitialContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit casting here is not needed and nothing happens at runtime if this isn't a valid cast anyway.
plugin/src/web.ts
Outdated
return { | ||
subscriptionRef: -0, | ||
topic: "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning null as any
is kind of a jerk move, we should return something here that isn't going make this a PITA to work with if a web developer is using the API outside of a Portals context during development.
feat: Make InitialContext.value T | undefined. This is to support that InitialContext will always be available when run in a portal context with at least the name value defined. This now makes
getInitialContext
an indicator to the web developers whether or not their code is being executed inside of a Portal or not without the native team having to provide any initialContext if it is not needed.BREAKING CHANGE
This is an API breaking change since InitialContext was initially assumed to always have a value provided if it was present. This is now changed so that we always provide access to the name of the portal to the web code to avoid there being strong coupling to the name.