Skip to content

Commit

Permalink
feat: add typescript mappings
Browse files Browse the repository at this point in the history
Also modernize the project and migrate it to gregberge/react-merge-refs.
  • Loading branch information
gregberge committed Jul 27, 2020
1 parent fae98bd commit 53480d2
Show file tree
Hide file tree
Showing 20 changed files with 4,912 additions and 2,864 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: gregberge
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 👉 [Please follow one of these issue templates](https://github.com/gregberge/react-merge-refs/issues/new/choose) 👈

Note: to keep the backlog clean and actionable, issues may be immediately closed if they do not follow one of the above issue templates.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: 🐛 Bug report
about: Create a report to help us improve
---

## 🐛 Bug Report

A clear and concise description of what the bug is.

## To Reproduce

Steps to reproduce the behavior:

## Expected behavior

A clear and concise description of what you expected to happen.

## Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

## Run `npx envinfo --system --binaries --npmPackages react-merge-refs,react,react-dom --markdown --clipboard`

Paste the results here:

```bash

```
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: 🚀 Feature Proposal
about: Submit a proposal for a new feature
---

## 🚀 Feature Proposal

A clear and concise description of what the feature is.

## Motivation

Please outline the motivation for the proposal.

## Example

Please provide an example for how this feature would be used.

## Pitch

Why does this feature belong in the react-merge-refs ecosystem?
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: 💬 Questions / Help
about: If you have questions, please read full readme first
---

## 💬 Questions and Help

This project project is young, but please before asking your question:

- Read carefully the README of the project
- Search if your answer has already been answered in old issues

After you can submit your question and we will be happy to help you!
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/regression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: 💥 Regression Report
about: Report unexpected behavior that worked in previous versions
---

## 💥 Regression Report

A clear and concise description of what the regression is.

## Last working version

Worked up to version:

Stopped working in version:

## To Reproduce

Steps to reproduce the behavior:

## Expected behavior

A clear and concise description of what you expected to happen.

## Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

## `npx envinfo --system --binaries --npmPackages react-merge-refs,react,react-dom --markdown --clipboard`

Paste the results here:

```bash

```
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->

## Summary

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

## Test plan

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->
6 changes: 3 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
!/dist/**/*.js
!/src/**/*.js
*.test.js
!/dist/**/*.{ts,js,map}
!/src/**/*.tsx?
**/*.test.tsx
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
language: node_js

node_js:
- 10
- 14

branches:
only:
- "master"

notifications:
email: false

cache:
yarn: true
directories:
- 'node_modules'
- "node_modules"

git:
depth: 5
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ All notable changes to this project will be documented in this file. See [standa

## 1.0.0 (2019-09-19)


### Features

* first version ([f8d7132](https://github.com/smooth-code/react-merge-refs/commit/f8d7132))
- first version ([f8d7132](https://github.com/gregberge/react-merge-refs/commit/f8d7132))
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# How to Contribute

react-merge-refs is a small project, it uses [tsdx](https://github.com/jaredpalmer/tsdx) to simplify the development.

## [Code of Conduct](https://github.com/gregberge/react-merge-refs/blob/master/CODE_OF_CONDUCT.md)

We expect project participants to adhere to our Code of Conduct. Please read [the full text](https://github.com/gregberge/react-merge-refs/blob/master/CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated.

## Open Development

All work on react-merge-refs happens directly on [GitHub](/). Both core team members and external contributors send pull requests which go through the same review process.

### Workflow and Pull Requests

_Before_ submitting a pull request, please make sure the following is done…

1. Fork the repo and create your branch from `master`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/

Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:

```sh-session
$ git clone https://github.com/<your_username>/react-merge-refs
$ cd react-merge-refs
$ git checkout -b my_branch
```

Note: Replace `<your_username>` with your GitHub username

2. This project uses [Yarn](https://code.fb.com/web/yarn-a-new-package-manager-for-javascript/) for running development scripts. If you haven't already done so, please [install yarn](https://yarnpkg.com/en/docs/install).

3. Run `yarn install`. On Windows: To install [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may need to download either node.js or Chocolatey<br />

```sh
yarn install
```

To check your version of Yarn and ensure it's installed you can type:

```sh
yarn --version
```

4. If you've added code that should be tested, add tests.

5. If you've changed APIs, update the documentation.

6. Ensure the test suite passes via `yarn test`.

```sh-session
$ yarn test
```

## Bugs

### Where to Find Known Issues

We will be using GitHub Issues for our public bugs. We will keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new issue, try to make sure your problem doesn't already exist.

### Reporting New Issues

The best way to get your bug fixed is to provide a reduced test case. Please provide a public repository with a runnable example.

## Code Conventions

This project uses [Prettier](https://prettier.io/).

## License

By contributing to this project, you agree that your contributions will be licensed under its MIT license.
22 changes: 18 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
Copyright 2019 Smooth Code
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copyright (c) 2020 Greg Bergé

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# react-merge-refs

[![License](https://img.shields.io/npm/l/react-merge-refs.svg)](https://github.com/smooth-code/react-merge-refs/blob/master/LICENSE)
[![License](https://img.shields.io/npm/l/react-merge-refs.svg)](https://github.com/gregberge/react-merge-refs/blob/master/LICENSE)
[![npm package](https://img.shields.io/npm/v/react-merge-refs/latest.svg)](https://www.npmjs.com/package/react-merge-refs)
[![Build Status](https://img.shields.io/travis/smooth-code/react-merge-refs.svg)](https://travis-ci.org/smooth-code/react-merge-refs)
[![DevDependencies](https://img.shields.io/david/dev/smooth-code/react-merge-refs.svg)](https://david-dm.org/smooth-code/react-merge-refs?type=dev)
[![Build Status](https://img.shields.io/travis/gregberge/react-merge-refs.svg)](https://travis-ci.org/gregberge/react-merge-refs)
[![DevDependencies](https://img.shields.io/david/dev/gregberge/react-merge-refs.svg)](https://david-dm.org/gregberge/react-merge-refs?type=dev)

React utility to merge refs 🖇

Expand All @@ -14,13 +14,13 @@ npm install react-merge-refs
## Example

```js
import React from 'react'
import mergeRefs from 'react-merge-refs'
import React from "react";
import mergeRefs from "react-merge-refs";

const Example = React.forwardRef(function Example(props, ref) {
const localRef = React.useRef()
return <div ref={mergeRefs([localRef, ref])} />
})
const localRef = React.useRef();
return <div ref={mergeRefs([localRef, ref])} />;
});
```

## Why?
Expand Down
40 changes: 22 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@
"author": "Greg Bergé <berge.greg@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"umd:main": "dist/index.umd.js",
"module": "dist/index.mjs",
"source": "src/index.js",
"module": "dist/react-merge-refs.esm.js",
"typings": "dist/index.d.ts",
"repository": "github:gregberge/react-merge-refs",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/gregberge"
},
"scripts": {
"test": "jest",
"prebuild": "rm -rf dist/",
"build": "microbundle --external react",
"prepublishOnly": "yarn build",
"release": "standard-version && conventional-github-releaser --preset angular"
"release": "standard-version && conventional-github-releaser --preset angular",
"start": "tsdx watch",
"test": "tsdx test",
"build": "tsdx build"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"@testing-library/react": "^9.1.4",
"babel-core": "^7.0.0-0",
"babel-jest": "^24.9.0",
"@testing-library/react": "^10.4.7",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.7",
"conventional-github-releaser": "^3.1.3",
"jest": "^24.9.0",
"microbundle": "^0.11.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"standard-version": "^7.0.0"
"jest": "^26.1.0",
"microbundle": "^0.12.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"standard-version": "^8.0.2",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^3.8.3"
}
}
23 changes: 0 additions & 23 deletions src/index.test.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from "react";
import { render } from "@testing-library/react";
import mergeRefs from ".";

test("mergeRefs", () => {
const Dummy = React.forwardRef(function Dummy(_, ref) {
React.useImperativeHandle(ref, () => "refValue");
return null;
});
const refAsFunc = jest.fn();
const refAsObj = { current: undefined };
const Example: React.FC<{ visible: boolean }> = ({ visible }) => {
return visible ? <Dummy ref={mergeRefs([refAsObj, refAsFunc])} /> : null;
};
const { rerender } = render(<Example visible />);
expect(refAsFunc).toHaveBeenCalledTimes(1);
expect(refAsFunc).toHaveBeenCalledWith("refValue");
expect(refAsObj.current).toBe("refValue");
rerender(<Example visible={false} />);
expect(refAsFunc).toHaveBeenCalledTimes(2);
expect(refAsFunc).toHaveBeenCalledWith(null);
expect(refAsObj.current).toBe(null);
});
Loading

0 comments on commit 53480d2

Please sign in to comment.