-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Frame] Refactor to use createContext API #803
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
Conversation
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.
I'm noticing an issue where TypeScript
yells at me for polaris
and context
being missing from ContextualSaveBar
props in tests. Possibly related, I have to pull polaris
and context
out of this.props
in ContextualSaveBar
lifecycle methods. Anyone understand what is going on here?
src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx
Outdated
Show resolved
Hide resolved
src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx
Outdated
Show resolved
Hide resolved
src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx
Outdated
Show resolved
Hide resolved
src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx
Outdated
Show resolved
Hide resolved
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.
Also feeling a little weird about putting everything onto a context
object in props
. @AndrewMusgrave can you explain the thinking behind this a bit? Does this feel right to you to keep as a pattern?
I believe the |
Looks like the typing issue was to do with using the wrong version of TS in VSCode. So that problem is resolved. @dleroux this is still a WIP, so I haven't updated the other tests yet. Those tests failing was expected. |
Seems there is an issue with
I think this will be ok to keep as a pattern. Rather than directly using a render prop this'll allow us to keep our render logic cleaner and force similar implementations across context usage. If we decide to change something in the future we'll only have to change it in the HoC. And this'll allow us to use the same injector pattern we're familiar with (e.g. withAppProvider, withSticky). I decided to call the prop It's a very common pattern to pass context down as props, it's just not normally called context. You'll see it in most major libraries, for example |
That rationale makes sense to me @AndrewMusgrave. Would you see us moving |
bce98c3
to
186d479
Compare
d0a78a2
to
db45545
Compare
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.
I left a few comments, and we'll probably want to squash the commits but it's looking good!
Would you see us moving polaris context under the context object once we refactor AppProvider to use the new context API?
It definitely could live there but it seems we currently use it for more app level utilities and configuration. We originally moved properties inside polaris, like easdk
for example to namespace it. So we would be losing that.
}; | ||
contextualSaveBar.setProps({...newProps}); | ||
expect(frame.setContextualSaveBar).toHaveBeenCalledWith({ | ||
frame.setProps({ |
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.
Just curious, why do we need to setProps
on frame now?
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.
This is an alternative to mounting and unmounting the child component, since we no longer have direct access to the child component. Calling setProps
on Frame with children that have new props triggers the componentDidUpdate
lifecycle method for those children.
src/components/Frame/utilities/createFrameContext/createFrameContext.ts
Outdated
Show resolved
Hide resolved
db45545
to
876a8f2
Compare
7da2a27
to
c43b6e1
Compare
Would you be able to fire up a PR for this? Telling people to stick with TS 3.1.x is a bit rubbish |
I took a little stab at improving the typing of decorators, I think having the following types should allow you to grab just the static types on the decorated component: type StaticFields<Object> = {
[Key in keyof Object]: Key extends 'prototype' ? never : Key
}[keyof Object];
type Statics<Object> = Pick<Object, StaticFields<Object>>;
// Example
class MyComponent extends React.Component {
static foo = 'bar';
static Baz(qux: string) {
return <div>{qux}</div>;
}
render() {
return null;
}
}
type StaticMembers = Statics<typeof MyComponent>; // {foo: string; Baz: () => JSX.Element} |
c43b6e1
to
28a8bbe
Compare
28a8bbe
to
e135bdf
Compare
@dleroux, @AndrewMusgrave, @tmlayton this is ready for another look |
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.
LGTM 👍
onDismiss(): void; | ||
} | ||
|
||
export interface ToastID { |
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.
We use the {id: string}
interface a lot. Maybe it would be worth it to bring this out to the main type file and name it ID
?
@lemonmade is the Apollo issue preventing |
Yes, we've shipped and reverted the Apollo upgrade several times so we are getting close, but it is currently blocking. |
Want to create a 4.0 branch and target it with this PR? |
e135bdf
to
6409c60
Compare
Addresses #785.