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


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


Expand Down
2 changes: 1 addition & 1 deletion packages/examples/all/src/index.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function startApp(C: typeof App.AppComponent) {
if (targetEl == null) if (targetEl == null)
throw new Error('React app target element not found. Wrong HTML file?') 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) { if (module.hot) {
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/all/src/player/index.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const TimeLine = ({
class App extends React.Component<{ state: Atom<AppState> }, {}> { class App extends React.Component<{ state: Atom<AppState> }, {}> {
audioModel: AudioModel audioModel: AudioModel


componentWillMount() { // eslint-disable-next-line camelcase
UNSAFE_componentWillMount() {
this.audioModel = new AudioModel(this.props.state, audioSrc) 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 Original file line Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class App {


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


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


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


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


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


return r as LiftedIntrinsics return r as LiftedIntrinsics
} }
Expand Down