Skip to content

remove sComponentX overrides from RectComponent #62

@chandu0101

Description

@chandu0101

Currently in ReactComponent we have override methods for componentWillUpdate,shouldComponentUpdate componentDidUpdate, componentWillReceiveProps just to get scala props/state from wrapper JSProps/JSState

 class ReactComponent extends .. {
   @JSName("sComponentWillUpdate")
  def componentWillUpdate(nextProps: P, nextState: S): Unit = ()

  @JSName("componentWillUpdate")
  override def jsComponentWillUpdate(nextProps: Props,
                                     nextState: State): Unit = {
    componentWillUpdate(nextProps.sprops, nextState.sstate)
  }

  @JSName("sShouldComponentUpdate")
  def shouldComponentUpdate(nextProps: P, nextState: S): Boolean = true

  @JSName("shouldComponentUpdate")
  override def jsShouldComponentUpdate(nextProps: Props,
                                       nextState: State): Boolean = {
    shouldComponentUpdate(nextProps.sprops, nextState.sstate)
  }

  @JSName("sComponentDidUpdate")
  def componentDidUpdate(prevProps: P, prevState: S): Unit = ()

  @JSName("componentDidUpdate")
  override def jsComponentDidUpdate(prevProps: Props, prevState: State): Unit = {
    componentDidUpdate(prevProps.sprops, prevState.sstate)
  }

  @JSName("sComponentWillReceiveProps")
  def componentWillReceiveProps(nextProps: P): Unit = ()

  @JSName("componentWillReceiveProps")
  override def jsComponentWillReceiveProps(nextProps: Props): Unit = {
    componentWillReceiveProps(nextProps.sprops)
  }

}

When ever a component updated via setState they will be called. even though implementation is just unit () we still paying method call! and user component should annotate method with @JSName("sShouldComponentUpdate"), etc how about removing this overrides ?

Current User Component with overrides of sComponetX

class HeaderComponent extends ReactComponent {

    @JSName("sShouldComponentUpdate")
  override def shouldComponentUpdate(nextProps: P,
                                       nextState: S): Boolean = {
   (nexProps ne props) && (nextState ne state)
  }

}

New after removing overrides from ReactComponent

class HeaderComponent extends ReactComponent {

  override def shouldComponentUpdate(nextJSProps: JSProps[P],
                                       nextJSState: JSState[S]): Boolean = {
 (nextJSProps.sprops ne props) && (nextJSState.sstate ne state)
  }

this way we can eliminate extra method calls , and no JSName annotations required, but user should call .sprops/.sstate when they need scala props/state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions