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

Fix double re-render in LiftWrapper and migrate it to PureComponent #82

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
logs
*.log
npm-debug.log*
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/all/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import { Atom, Lens } from '@grammarly/focal'

interface ExampleComponent<S> {
Component: React.StatelessComponent<{ state: Atom<S> }>
Component: React.FunctionComponent<{ state: Atom<S> }>
defaultState: S
}

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/all/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function startApp(C: typeof App.AppComponent) {
if (targetEl == null)
throw new Error('React app target element not found. Wrong HTML file?')

ReactDOM.render(<C state={appState} />, targetEl)
ReactDOM.render(<React.StrictMode><C state={appState} /></React.StrictMode>, targetEl)
}

if (module.hot) {
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/all/src/player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const TimeLine = ({
class App extends React.Component<{ state: Atom<AppState> }, {}> {
audioModel: AudioModel

componentWillMount() {
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount() {
this.audioModel = new AudioModel(this.props.state, audioSrc)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/todomvc/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class App {

start() {
ReactDOM.render(
<AppComponent model={this._model}/>,
<React.StrictMode><AppComponent model={this._model}/></React.StrictMode>,
this._targetElement
)
}
Expand Down
12 changes: 6 additions & 6 deletions packages/focal/src/react/intrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import * as React from 'react'
import { ObservableReactHTMLProps, ObservableReactChildren } from './observablePropTypes'
import { LiftWrapperProps, LiftWrapper } from './react'
import { LiftWrapper } from './react'

export interface LiftedIntrinsicComponentProps<E> extends ObservableReactHTMLProps<E> {
mount?: React.Ref<E>
Expand All @@ -15,7 +15,7 @@ export interface LiftedIntrinsicComponentProps<E> extends ObservableReactHTMLPro
export interface LiftedIntrinsic<
E extends Element, A extends React.HTMLAttributes<E> = React.AllHTMLAttributes<E>> {
(props: LiftedIntrinsicComponentProps<E>):
React.ReactElement<LiftWrapperProps<ObservableReactHTMLProps<E, A>>>
React.ReactElement<LiftWrapper.Props<ObservableReactHTMLProps<E, A>>>
}

export function liftIntrinsic<
Expand All @@ -25,8 +25,8 @@ export function liftIntrinsic<
intrinsicClassName: K
): LiftedIntrinsic<E> {
return (props: LiftedIntrinsicComponentProps<E>) =>
React.createElement<LiftWrapperProps<ObservableReactHTMLProps<E>>>(
LiftWrapper,
React.createElement<LiftWrapper.Props<ObservableReactHTMLProps<E>>>(
LiftWrapper.Renderer,
{ component: intrinsicClassName, props: props }
)
}
Expand All @@ -45,7 +45,7 @@ export interface LiftedFragmentAttributes extends ObservableReactChildren, React
export interface LiftedFragment {
(props: LiftedFragmentAttributes):
// @TODO this probably isn't a correct type for it
React.ReactElement<LiftWrapperProps<ObservableReactHTMLProps<{}>>>
React.ReactElement<LiftWrapper.Props<ObservableReactHTMLProps<{}>>>
}

interface ExtraLiftedIntrinsics {
Expand Down Expand Up @@ -79,7 +79,7 @@ export function createLiftedIntrinsics(): LiftedIntrinsics {
)

r.Fragment = (props: LiftedFragmentAttributes) =>
React.createElement(LiftWrapper, { component: React.Fragment, props })
React.createElement(LiftWrapper.Renderer, { component: React.Fragment, props })

return r as LiftedIntrinsics
}
Expand Down
Loading