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

Update context #1462

Merged
Merged

Conversation

AndrewMusgrave
Copy link
Member

@AndrewMusgrave AndrewMusgrave commented May 13, 2019

WHY are these changes introduced?

Updating some context conversions described in #1403.

  • export the result of React.createContext rather than provider/consumer
  • use {Component}/context.tsx rather than {Component}/Components/Context/Context.tsx
  • create the context type in the context file rather than a shared types file
  • describe the context object in the render method to be more in line with function style components

WHAT is this pull request doing?

As described above for all contexts excluding withRef, which will be removed in v4.

Notes

  • Kept my combines separate for now in case it makes 🎩 / review easier

@BPScott BPScott temporarily deployed to polaris-react-pr-1462 May 13, 2019 15:22 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1462 May 13, 2019 15:26 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1462 May 13, 2019 15:37 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1462 May 13, 2019 15:44 Inactive
@AndrewMusgrave AndrewMusgrave changed the title [Test] Update context Update context May 13, 2019
@AndrewMusgrave AndrewMusgrave added the 🤖Skip Changelog Causes CI to ignore changelog update check. label May 13, 2019
@AndrewMusgrave
Copy link
Member Author

Ignore the weird branch name 😄 I was running into some issues when I renamed a file to the same name with a casing change 😅

@AndrewMusgrave AndrewMusgrave self-assigned this May 13, 2019
@AndrewMusgrave AndrewMusgrave added this to the v4.0.0 milestone May 13, 2019
Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Fantastic stuff! This feels cleaner than having components and paves the way for us using useContext in the future as we consider writing functional components.

Most comments here are around places where we can omit specifying a type on an object because the Context.Provider will already provide typechecking for us.

I've also dropped two thoughts on how we could simplify WithinContentContext by renaming it and moving it into Banner, strictly speaking that's a little outside the scope of this PR so up to you on if you want to act on it here or later.

I'd like to say our eventual end goal is not needing HoC wrappers as they make things confusing. Now that modern context is easy to consume I'd be interested in killing off WithContext and replacing it with apps using the context consumer directly, but that's a story for another PR too :)

src/components/Card/Card.tsx Outdated Show resolved Hide resolved
src/components/DropZone/DropZone.tsx Outdated Show resolved Hide resolved
src/components/Frame/Frame.tsx Outdated Show resolved Hide resolved
src/components/Navigation/Navigation.tsx Outdated Show resolved Hide resolved
src/components/Scrollable/Scrollable.tsx Outdated Show resolved Hide resolved
src/components/ThemeProvider/ThemeProvider.tsx Outdated Show resolved Hide resolved
}

const WithinContentContext = React.createContext<WithinContentContextType>({
withinContentContainer: false,
Copy link
Member

Choose a reason for hiding this comment

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

Not quite related to this PR but:

Can this be a boolean instead of an object? I can't see us ever needing to add extra values into this.

const WithinContentContext = React.createContext(false);

@@ -1 +1,4 @@
export {Provider, Consumer, WithinContentContext} from './WithinContentContext';
import WithinContentContext from './context';
Copy link
Member

Choose a reason for hiding this comment

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

This isn't totally strictly related to this PR but i'm not convinced by this component. Acting on this feedback can be done either in this PR or in a new one I don't mind :)

Creating a component that's not really a component, it's just a context feels odd to me. Because it's just a stand alone component it has no uh, context on what it's used for.

What do you think to exposing this from Banner? Things that want to set this state like Card can do `import {BannerContentContainer} from 'Banner'. That might help hint that this is used within Banner.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that approach, it does feel odd having a stand-alone "component" to create the context. I'll add this to the issue

@BPScott
Copy link
Member

BPScott commented May 14, 2019

Just spotted this is getting merged into appprovider-new-context rather than the v4 branch, so yeah ignore that musing on WithinContentContext and do it in a follow up PR.

@AndrewMusgrave
Copy link
Member Author

Most comments here are around places where we can omit specifying a type on an object because the Context.Provider will already provide typechecking for us.

Originally I added the types for faster type errors while editing context but if others don't see value in it I'm 👌 with just having the type inferred 😄

Just spotted this is getting merged into appprovider-new-context rather than the v4 branch, so yeah ignore that musing on WithinContentContext and do it in a follow up PR.

I'll create a polish issue 👍

@BPScott BPScott temporarily deployed to polaris-react-pr-1462 May 14, 2019 14:17 Inactive
Convert ScrollTo

Remove dropzone context from index

Convert navigation

Convert combobox

Convert withincontext

Update frame context

Update resourcelist context

Update themeprovider context

Update appprovider context

Touchups

changelog

Update appprovider context type

Rename file
@AndrewMusgrave AndrewMusgrave merged commit f1565a7 into appprovider-new-context May 14, 2019
@AndrewMusgrave AndrewMusgrave deleted the new-context-style-new-branch branch May 14, 2019 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖Skip Changelog Causes CI to ignore changelog update check.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants