Skip to content

typings: withSize add onSize callback #167

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

Merged
merged 5 commits into from
Oct 21, 2019
Merged

typings: withSize add onSize callback #167

merged 5 commits into from
Oct 21, 2019

Conversation

beckend
Copy link
Contributor

@beckend beckend commented May 7, 2019

No description provided.

@codecov
Copy link

codecov bot commented May 7, 2019

Codecov Report

Merging #167 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #167   +/-   ##
=======================================
  Coverage   90.56%   90.56%           
=======================================
  Files           4        4           
  Lines         106      106           
  Branches       25       25           
=======================================
  Hits           96       96           
  Misses          9        9           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d433fdd...eec7596. Read the comment docs.

@beckend
Copy link
Contributor Author

beckend commented May 12, 2019

@ctrlplusb can you review?

Copy link
Owner

@ctrlplusb ctrlplusb left a comment

Choose a reason for hiding this comment

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

Thanks for starting this 👍

refreshRate?: number
refreshMode?: 'throttle' | 'debounce'
noPlaceholder?: boolean
readonly monitorWidth?: boolean
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure if there is any value marking these as read-only as they won't get exposed to the user. These configuration values are inputs.

size: {
width: number | null
height: number | null
readonly size: {
Copy link
Owner

Choose a reason for hiding this comment

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

Nice, good touch. 👍

}

export interface SizeMeRenderProps extends SizeMeOptions {
children: (props: SizeMeProps) => ReactElement
readonly children: (props: SizeMeProps) => ReactElement
Copy link
Owner

Choose a reason for hiding this comment

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

Same here, this is user provided, and won't get exposed in a manner that the user could modify it, so the readonly isn't really useful in this case.

}

export class SizeMe extends Component<SizeMeRenderProps> {}

export type WithSizeOnSizeArgs = [
Copy link
Owner

Choose a reason for hiding this comment

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

Could we rename this to Size and perhaps reuse the type within SizeMeProps?

}
]

export type WithSizeOnSizeCallback = (...x: WithSizeOnSizeArgs) => void
Copy link
Owner

Choose a reason for hiding this comment

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

You are spreading an array/tuple that contains a single item. Perhaps consider simplifying this (after the Size type refactor I recommended above) to the following:

export type OnSizeCallback = (size: Size) => void;

export type WithSizeOnSizeCallback = (...x: WithSizeOnSizeArgs) => void

export interface WithSizeProps {
readonly onSize?: WithSizeOnSizeCallback
Copy link
Owner

Choose a reason for hiding this comment

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

Same here regarding the readonly not really being useful as it's an input that doesn't get exposed to user again.

@@ -22,4 +22,8 @@ function MyComponent({ id, size }: MyComponentProps) {

const SizedMyComponent = withSize()(MyComponent)

const foo = <SizedMyComponent id={1} />
const onSize: WithSizeOnSizeCallback = ({ height, width }) => {
Boolean(height && width)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you replace the body of this with the following:

  if (width) {
    const foo = width + 1	    const foo = width + 1
  }	  }
  if (height) {	  if (height) {
    const foo = height + 1	    const foo = height + 1
  }	  }
  // typings:expect-error	  // typings:expect-error
  const h1 = height + 1	  const h1 = height + 1
  // typings:expect-error	  // typings:expect-error
  const w1 = width + 1	  const w1 = width + 1

This helps guard that width/height are nullable numbers.

@ctrlplusb
Copy link
Owner

@beckend reviewed :)

@codecov-io
Copy link

codecov-io commented May 17, 2019

Codecov Report

Merging #167 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #167   +/-   ##
=======================================
  Coverage   90.56%   90.56%           
=======================================
  Files           4        4           
  Lines         106      106           
  Branches       25       25           
=======================================
  Hits           96       96           
  Misses          9        9           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f030120...e5036f0. Read the comment docs.

@codecov-io
Copy link

Codecov Report

Merging #167 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #167   +/-   ##
=======================================
  Coverage   90.56%   90.56%           
=======================================
  Files           4        4           
  Lines         106      106           
  Branches       25       25           
=======================================
  Hits           96       96           
  Misses          9        9           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d433fdd...c285967. Read the comment docs.

@beckend
Copy link
Contributor Author

beckend commented May 17, 2019

@ctrlplusb sorry for the delay, life and stuff...
Anyway did the adjustments, I personally however would never allow argument mutation by default even if it is not being used, but I also understand that it is also trivial in this case.

@beckend
Copy link
Contributor Author

beckend commented Oct 11, 2019

The PR was done, however no action was taken.

@beckend beckend closed this Oct 11, 2019
@ctrlplusb ctrlplusb reopened this Oct 11, 2019
@ctrlplusb
Copy link
Owner

Hey @beckend

I still intend to merge this.

I just need to do some more planning around it.

Please leave open.

Thanks

@beckend
Copy link
Contributor Author

beckend commented Oct 11, 2019

Got it, just wanted to do some housecleaning.

@ctrlplusb ctrlplusb merged commit 76190da into ctrlplusb:master Oct 21, 2019
@beckend beckend deleted the typings_1 branch October 22, 2019 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants