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

docs: adding concept doc for concepts #168

Merged
merged 17 commits into from
Jan 29, 2025
Merged

docs: adding concept doc for concepts #168

merged 17 commits into from
Jan 29, 2025

Conversation

dereklegenzoff
Copy link
Contributor

Adds a conceptual doc on concepts and a simple example. Also makes minor tweaks to the basic concepts section on contexts.

It uses `jsx` to define and orchestrate workflows with functional, reusable components:
Contexts are particularly useful for:

- Sharing configuration across multiple components
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worthwhile calling out examples such as client singletons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is mentioned in the providers section below.

- Providing dependencies to deeply nested components without prop drilling
- Managing state that needs to be accessed by multiple components

GenSX also supports [Providers](../providers) which are a specialized use of contexts that focus on managing configuration and dependencies for your workflow. If you're managing external service configurations like API keys or client instances, you should use providers instead of raw contexts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives the impression that Providers aren't tightly coupled with context, when they really are. You can't (usefully) use a context without a provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point. I'll revise this. I probably also need to clean up some of the verbiage in the providers doc

async function main() {
// Provide a value to the context
const result = await gsx.execute(
<UserContext.Provider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think its worth demonstrating nesting providers, or just leave that up to the docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree we should probably show that you can nest providers and all values are available in the tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a short section in the docs

Copy link

cloudflare-workers-and-pages bot commented Jan 24, 2025

Deploying gensx with  Cloudflare Pages  Cloudflare Pages

Latest commit: 21ee570
Status: ✅  Deploy successful!
Preview URL: https://d95a0d12.gensx.pages.dev
Branch Preview URL: https://derek-concepts2.gensx.pages.dev

View logs

Copy link
Member

@EvanBoyle EvanBoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to clarify the difference between providers and context:

  • Context: defines what can be shared (a type and a default value)
  • Provider: sets the actual value for the context and takes care of passing it through the component tree to all children
  • gsx.useContext: how child components access context values from a provider

Is there a use case for using context without a provider?

Given all of this, I think it is worth asking ourselves whether it makes sense for there to be separate docs pages for these, or if we should just have a Context & Providers section.

@jmoseley
Copy link
Contributor

I think combined pages would be better. You can't have one without the other, they aren't standalone.

@dereklegenzoff
Copy link
Contributor Author

I was thinking something similar. I'll combine these into the same page.

@dereklegenzoff
Copy link
Contributor Author

thanks for all of the feedback! Just pushed a combined version of the docs. Hopefully a decent improvement.

Copy link
Member

@EvanBoyle EvanBoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good and I think we can ship it.

There are two things we didn't cover here:

  1. Mutating context
  2. When to use / not to use a context

For (1) I'm not sure how much there is to cover, and honestly we probably need to experiment a little bit more for ourselves to be certain. Thing could be tricky here as components are executed in parallel, so depending on the order of execution siblings may or may not see updates. I'm pretty sure that children will see updates.

For (2) it might be worth noting that using contexts makes components in your workflow less reusable since they depend on global state.

Honestly, I think we could leave both of these out for now until we have a little bit more experience ourselves, but thought I would mention.

docs/src/content/docs/concepts/contexts.mdx Outdated Show resolved Hide resolved
docs/src/content/docs/concepts/contexts.mdx Outdated Show resolved Hide resolved
@dereklegenzoff dereklegenzoff merged commit bb46bbe into main Jan 29, 2025
5 checks passed
@dereklegenzoff dereklegenzoff deleted the derek/concepts2 branch January 29, 2025 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants