Skip to content

Commit

Permalink
feat: add esm support
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound authored and jquense committed Jun 17, 2019
1 parent eb7c4b6 commit 2457bf3
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 231 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"presets": [["jason", { "runtime": false }]]
"presets": ["jason"],
"env": {
"esm": {
"presets": [["jason", { "modules": false }]],
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
lib
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm i -S uncontrollable
If you are a bit unsure on the _why_ of this module read the next section first. If you just want to see some real-world examples, check out [React Widgets](https://github.com/jquense/react-widgets) which makes [heavy use of this strategy](https://github.com/jquense/react-widgets/blob/5d1b530cb094cdc72f577fe01abe4a02dd265400/src/Multiselect.jsx#L521).

```js
import uncontrollable from 'uncontrollable'
import { uncontrollable } from 'uncontrollable'
```

### API
Expand All @@ -27,7 +27,7 @@ import uncontrollable from 'uncontrollable'
For every prop you indicate as uncontrollable, the returned component will also accept an initial, `default` value for that prop. For example, `open` can be left uncontrolled but the initial value can be set via `defaultOpen={true}` if we want it to start open.

```js
const uncontrollable = require('uncontrollable')
import { uncontrollable } from 'uncontrollable'

const UncontrolledCombobox = uncontrollable(Combobox, {
value: 'onChange',
Expand All @@ -54,7 +54,7 @@ A React hook that can be used in place of the above Higher order Component. It
returns a complete set of `props` which are safe to spread through to a child element.

```js
import useUncontrolled from 'uncontrollable/hook'
import { useUncontrolled } from 'uncontrollable'

const UncontrolledCombobox = props => {
// filters out defaultValue, defaultOpen and returns controlled
Expand Down Expand Up @@ -127,7 +127,7 @@ We want to just handle the open/onToggle case ourselves if the consumer doesn't
`uncontrollable` allows you separate out the logic necessary to create controlled/uncontrolled inputs letting you focus on creating a completely controlled input and wrapping it later. This tends to be a lot simpler to reason about as well.

```js
const uncontrollable = require('uncontrollable');
import { uncontrollable } from 'uncontrollable';

const UncontrollableDropdown = uncontrollable(SimpleDropdown, {
value: 'onChange',
Expand Down
162 changes: 0 additions & 162 deletions lib/index.js

This file was deleted.

59 changes: 0 additions & 59 deletions lib/utils.js

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"repository": "jquense/uncontrollable",
"license": "MIT",
"main": "lib/index.js",
"main": "cjs/index.js",
"module": "esm/index.js",
"keywords": [
"uncontrolled-component",
"react-component",
Expand All @@ -21,7 +22,9 @@
"test": "jest",
"tdd": "jest --watch",
"lint": "eslint src test",
"build": "rimraf lib && babel src --out-dir lib && cp package.json lib/",
"build:cjs": "NODE_ENV=production babel src --out-dir lib/cjs",
"build:esm": "NODE_ENV=production BABEL_ENV=esm babel src --out-dir lib/esm",
"build": "rimraf lib && yarn build:cjs && yarn build:esm && cp package.json lib/",
"prepublishOnly": "npm run build",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once"
Expand Down Expand Up @@ -62,6 +65,7 @@
"travis-deploy-once": "^5.0.11"
},
"dependencies": {
"@babel/runtime": "^7.4.5",
"invariant": "^2.2.4"
},
"release": {
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react'
import invariant from 'invariant'
import * as Utils from './utils'

export default function uncontrollable(
export { default as useUncontrolled } from './hook.js';

export function uncontrollable(
Component,
controlledValues,
methods = []
Expand Down
3 changes: 1 addition & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import React from 'react'
import Enzyme, { mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

import uncontrollable from '../src'
import useUncontrolled from '../src/hook'
import { uncontrollable, useUncontrolled } from '../src'

Enzyme.configure({ adapter: new Adapter() })

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,13 @@
pirates "^4.0.0"
source-map-support "^0.5.9"

"@babel/runtime@^7.4.5":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
integrity sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ==
dependencies:
regenerator-runtime "^0.13.2"

"@babel/template@^7.0.0", "@babel/template@^7.1.0", "@babel/template@^7.1.2", "@babel/template@^7.2.2":
version "7.2.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.2.2.tgz#005b3fdf0ed96e88041330379e0da9a708eb2907"
Expand Down Expand Up @@ -6828,6 +6835,11 @@ regenerator-runtime@^0.12.0:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==

regenerator-runtime@^0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447"
integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==

regenerator-transform@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.13.3.tgz#264bd9ff38a8ce24b06e0636496b2c856b57bcbb"
Expand Down

0 comments on commit 2457bf3

Please sign in to comment.