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: Update InitialContext #184

Merged
merged 2 commits into from
Nov 7, 2022
Merged

feat: Update InitialContext #184

merged 2 commits into from
Nov 7, 2022

Conversation

Steven0351
Copy link
Member

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.

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.
@vercel
Copy link

vercel bot commented Nov 7, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ionic-portals ✅ Ready (Inspect) Visit Preview Nov 7, 2022 at 8:35PM (UTC)

export function getInitialContext<T = unknown>(): InitialContext<T> | undefined {
return (window as any).portalInitialContext as { name: string, value: T; };
return (window as any).portalInitialContext;
Copy link
Member Author

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.

@vercel vercel bot temporarily deployed to Preview November 7, 2022 20:29 Inactive
return {
subscriptionRef: -0,
topic: ""
}
Copy link
Member Author

@Steven0351 Steven0351 Nov 7, 2022

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.

@vercel vercel bot temporarily deployed to Preview November 7, 2022 20:35 Inactive
@Steven0351 Steven0351 merged commit 7a49a9d into main Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants