Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Ref): extract to a separate package, add utils #1281

Merged
merged 13 commits into from
May 7, 2019

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented May 2, 2019

Fixes #998.


This PR:

  • moves Ref component to @stardust-ui/react-component-ref package, however Ref can be still accessed from @stardust-ui/react
  • adds isRefObject(), toRefObject() utils

@codecov
Copy link

codecov bot commented May 3, 2019

Codecov Report

Merging #1281 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1281      +/-   ##
==========================================
+ Coverage   72.73%   72.79%   +0.05%     
==========================================
  Files         736      738       +2     
  Lines        5633     5645      +12     
  Branches     1630     1655      +25     
==========================================
+ Hits         4097     4109      +12     
  Misses       1529     1529              
  Partials        7        7
Impacted Files Coverage Δ
packages/react/src/components/Input/Input.tsx 100% <ø> (ø) ⬆️
...ackages/react/src/components/Dropdown/Dropdown.tsx 87.75% <ø> (ø) ⬆️
...ckages/react/src/components/Popup/PopupContent.tsx 90.9% <ø> (ø) ⬆️
packages/react-component-ref/src/RefForward.tsx 100% <ø> (ø)
...react/src/components/RadioGroup/RadioGroupItem.tsx 100% <ø> (ø) ⬆️
packages/react-component-ref/src/RefFindNode.tsx 100% <ø> (ø)
packages/react/src/components/Dialog/Dialog.tsx 0% <ø> (ø) ⬆️
...ages/react/test/specs/commonTests/isConformant.tsx 93.39% <ø> (ø) ⬆️
packages/react/src/components/Popup/Popup.tsx 68.29% <ø> (ø) ⬆️
packages/react/src/components/Portal/Portal.tsx 95% <ø> (ø) ⬆️
... and 14 more

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 614a411...477e532. Read the comment docs.

@DustyTheBot
Copy link
Collaborator

DustyTheBot commented May 3, 2019

Warnings
⚠️ New package.json added: packages/react-component-ref/package.json. Make sure you have approval before merging!
⚠️ Package (or peer) dependencies changed. Make sure you have approval before merging!

Changed dependencies in packages/react/package.json

package before after
@stardust-ui/react-component-ref - ^0.29.1

Generated by 🚫 dangerJS

},
"publishConfig": {
"access": "public"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI @miroslavstastny publishConfig is defined

@@ -1,14 +1,14 @@
import * as customPropTypes from '@stardust-ui/react-proptypes'
import * as PropTypes from 'prop-types'
import * as React from 'react'
import { isForwardRef } from 'react-is'
import * as ReactIs from 'react-is'
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: To be common with other imports

if (ref !== null && typeof ref === 'object') {
// The `current` property is defined as readonly, however it's a valid way because
// `ref` is a mutable object
;(ref as React.MutableRefObject<N>).current = node
Copy link
Member Author

Choose a reason for hiding this comment

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

Only this line was changed: we don't need @ts-ignore more because MutableRefObject was introduced to typings

@@ -20,10 +21,10 @@ export default class RefFindNode extends React.Component<RefFindNodeProps> {

static propTypes = {
children: PropTypes.element.isRequired,
innerRef: customPropTypes.ref,
innerRef: customPropTypes.ref.isRequired as PropTypes.Validator<React.Ref<any>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1,7 +1,7 @@
import { RefForward } from '@stardust-ui/react-component-ref'
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like that we have inconsistency between the imports in these tests vs the imports in the components' tests. Can we change this import or is there a reason why it is like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

We want to test public APIs and get rid of src alias: it creates issues with IDE and works only in Jest/Webpack.

/cc @kuzhelov

@@ -1,5 +1,5 @@
import { handleRef } from '@stardust-ui/react-component-ref'
Copy link
Contributor

Choose a reason for hiding this comment

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

See the prev comment for the import

@@ -0,0 +1,27 @@
import * as React from 'react'

const nullRefObject: React.RefObject<null> = { current: null }
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user uses reference like this in the following way: ref.current.focus()? How is it safe to have a nullRefObject?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can be null by typings:

    interface RefObject<T> {
        readonly current: T | null;
    }
    // Mutable it used in hooks an initial value is obviously defined
    // React.useRef(null)
    interface MutableRefObject<T> {
        current: T;
    }

CHANGELOG.md Outdated
@@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Features
- `Ref` component extracted to a `@stardust-ui/react-component-ref` @layershifter ([#1281](https://github.com/stardust-ui/react/pull/1281))
- added `isRefObject()`, `toRefObject()` and `unstable_mergeRefs()` utils for React refs @layershifter ([#1281](https://github.com/stardust-ui/react/pull/1281))
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are not sure about this method, why even adding it with the unstable_ prefix? Is this blocker on client's side? I really don't see the things mention in the PR description as a valid points for adding it...

Copy link
Contributor

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Approving the changes. As agreed offline, we will not add the unstable_mergeRefs() for now, until we are certain of it's API and usage.

@layershifter layershifter merged commit 7eac364 into master May 7, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat/extract-ref-compomnent branch May 7, 2019 09:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Ref utils
3 participants