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

Create index.d.ts #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions packages/components/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import { ReactNode } from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that this import is obsolete since you are only accessing ReactNode via React a few lines below.


export interface ViewportTrackerProps {
children: React.ReactNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

tabWidth is set to 2 for JS files. It would be great if we can stick to the same for this file as well.

}
export class ViewportTracker extends React.Component<ViewportTrackerProps> {}


export interface ViewportAwareComponentProps {
/**
* Determines pre-triggering of inViewport. Useful for rendering components beforehand to improve user experience. A ratio of 0.5 means that the effective viewport will be twice the size of the real viewport.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment should probably be split into several lines.

*/
preTriggerRatio?: number = 0
/**
* Invoked when the component enters the viewport.
*/
onViewportEnter?: () => void
/**
* Invoked when the component leaves the viewport.
*/
onViewportLeave?: () => void
/**
* Allows access to the reference of the wrapped component.
*/
innerRef?: React.Ref
}
export class ViewportAware<P> extends React.Component<ViewportAwareComponentProps & P> {}
Copy link
Collaborator

@bevkoski bevkoski Nov 21, 2019

Choose a reason for hiding this comment

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

Why are all of the classes and interfaces exported? Isn't the const Viewport export at the bottom sufficient?


export interface ViewportAwarePlaceholderProps {
/**
* Placeholder that can override the one provided on construction
*/
placeholder?: React.Component
/**
* Whether to keep the wrapped component displayed once it enters the viewport.
*/
retainOnceInViewport?: boolean
}
export class ViewportAwarePlaceholder extends React.Component<ViewportAwarePlaceholderProps> {}



Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great if you can unify the number of blank lines between the code blocks in the file. There are a total of 3 here and a total of 2 at line 9. One blank line is enough. Ideally, we should have TSLint setup, but that is not absolutely necessary at the moment.

export const Viewport = {
Tracker: ViewportTracker,
Aware: (component: typeof React.Component) => ViewportAware,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is typeof necessary and if so, why isn't it used one line below, for the WithPlaceholder HoC as well?

WithPlaceholder: (image: React.Component, placeholder: React.Component) => ViewportAwarePlaceholder
Copy link
Collaborator

Choose a reason for hiding this comment

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

The wrapped component can be something other than image as well, so I would replace image with component. Also, the placeholder argument should be optional.

}