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

chore!: Flatten imports #314

Merged
merged 2 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 0 additions & 16 deletions .babelrc

This file was deleted.

18 changes: 18 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = (api) => ({
presets: [
[
'@4c',
{
targets: {},
modules: api.env() === 'esm' ? false : 'commonjs',
},
],
],
plugins: [api.env() !== 'esm' && 'add-module-exports'].filter(Boolean),

env: {
test: {
plugins: ['istanbul'],
},
},
});
9 changes: 2 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"extends": [
"4catalyzer",
"prettier"
],
"plugins": [
"prettier"
],
"extends": ["4catalyzer", "prettier"],
"plugins": ["prettier"],
"env": {
"browser": true
},
Expand Down
92 changes: 87 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,121 @@
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Transpiled code
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

# Transpiled code.
/lib

# Yalc.
.yalc/
yalc.lock
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ Farce provides a [Redux](http://redux.js.org/) store enhancer that wraps a serie

[![Codecov][codecov-badge]][codecov]

<!-- prettier-ignore-start -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Usage](#usage)
- [Guide](#guide)
- [Installation](#installation)
- [Basic usage](#basic-usage)
- [Protocols](#protocols)
- [`BrowserProtocol`](#browserprotocol)
- [`HashProtocol`](#hashprotocol)
- [`ServerProtocol`](#serverprotocol)
- [`MemoryProtocol`](#memoryprotocol)
- [Middlewares](#middlewares)
- [`queryMiddleware` and `createQueryMiddleware`](#querymiddleware-and-createquerymiddleware)
- [`createBasenameMiddleware`](#createbasenamemiddleware)
- [Locations and location descriptors](#locations-and-location-descriptors)
- [Navigation listeners](#navigation-listeners)
- [Transient state storage](#transient-state-storage)
- [Minimizing bundle size](#minimizing-bundle-size)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- prettier-ignore-end -->

## Usage

```js
Expand Down Expand Up @@ -216,8 +241,11 @@ const location = store.farce.createLocation('/foo?the=query');
The `farce` object on the store also has an `addNavigationListener` method. This method takes a navigation listener function and an optional options object and returns a function to remove the navigation listener.

```js
const removeNavigationListener = store.farce.addNavigationListener(location =>
location.pathname === '/bar' ? 'Are you sure you want to go to /bar?' : true,
const removeNavigationListener = store.farce.addNavigationListener(
(location) =>
location.pathname === '/bar'
? 'Are you sure you want to go to /bar?'
: true,
);

// To remove the navigation listener:
Expand All @@ -236,7 +264,7 @@ When adding a navigation listener, you can set the `beforeUnload` option to run

```js
store.farce.addNavigationListener(
location => {
(location) => {
if (location === null) {
return false;
}
Expand Down Expand Up @@ -273,12 +301,12 @@ const value3 = stateStorage.read(location, 'bar');

### Minimizing bundle size

The top-level `farce` package exports everything available in this library. It is unlikely that any single application will use all the features available. As such, for real applications, you should import the modules you need from `farce/lib` directly, to pull in only the code that you use.
The top-level `farce` package exports everything available in this library. It is unlikely that any single application will use all the features available. As such, for real applications, you should import the modules you need directly, to pull in only the code that you use.

```js
import BrowserProtocol from 'farce/lib/BrowserProtocol';
import createHistoryEnhancer from 'farce/lib/createHistoryEnhancer';
import queryMiddleware from 'farce/lib/queryMiddleware';
import BrowserProtocol from 'farce/BrowserProtocol';
import createHistoryEnhancer from 'farce/createHistoryEnhancer';
import queryMiddleware from 'farce/queryMiddleware';

// Instead of:
// import {
Expand Down
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
],
"main": "lib/index.js",
"scripts": {
"build": "babel src -d lib --delete-dir-on-start",
"build": "rimraf lib && yarn build:cjs && yarn build:esm && yarn build:pick",
"build:cjs": "babel src -d lib/cjs",
"build:esm": "babel src -d lib/esm --env-name esm",
"build:pick": "cherry-pick ../src --cjs-dir=cjs --esm-dir=esm --cwd=lib",
"lint": "eslint examples/*/src src test *.js",
"prepublish": "npm run build",
"release": "rollout",
"tdd": "cross-env NODE_ENV=test karma start",
"test": "npm run lint && npm run testonly",
"testonly": "npm run tdd -- --single-run"
Expand All @@ -20,13 +24,18 @@
}
},
"lint-staged": {
"*.js": "eslint --fix"
"*.js": "eslint --fix",
"*.md": "prettier --write",
"README.md": "doctoc"
},
"prettier": {
"printWidth": 79,
"singleQuote": true,
"trailingComma": "all"
},
"publishConfig": {
"directory": "lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/4Catalyzer/farce.git"
Expand All @@ -49,17 +58,20 @@
},
"devDependencies": {
"@4c/babel-preset": "^7.3.4",
"@4c/rollout": "^2.1.4",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/polyfill": "^7.8.7",
"babel-loader": "^8.1.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-istanbul": "^6.0.0",
"chai": "^4.2.0",
"cherry-pick": "^0.5.0",
"codecov": "^3.6.5",
"cross-env": "^7.0.2",
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"doctoc": "^1.4.0",
"eslint": "^6.8.0",
"eslint-config-4catalyzer": "^1.1.1",
"eslint-config-prettier": "^6.10.1",
Expand All @@ -79,6 +91,7 @@
"mocha": "^7.1.1",
"p-defer": "^3.0.0",
"prettier": "^2.0.1",
"rimraf": "^3.0.2",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
"webpack": "^4.42.0"
Expand Down
2 changes: 1 addition & 1 deletion src/BrowserProtocol.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import invariant from 'invariant';

import createPath from './utils/createPath';
import createPath from './createPath';

export default class BrowserProtocol {
constructor() {
Expand Down
4 changes: 2 additions & 2 deletions src/HashProtocol.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import invariant from 'invariant';

import StateStorage from './StateStorage';
import createPath from './utils/createPath';
import ensureLocation from './utils/ensureLocation';
import createPath from './createPath';
import ensureLocation from './ensureLocation';

export default class HashProtocol {
constructor() {
Expand Down
4 changes: 2 additions & 2 deletions src/MemoryProtocol.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import invariant from 'invariant';

import createPath from './utils/createPath';
import ensureLocation from './utils/ensureLocation';
import createPath from './createPath';
import ensureLocation from './ensureLocation';

const STATE_KEY = '@@farce/state';

Expand Down
4 changes: 2 additions & 2 deletions src/ServerProtocol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createPath from './utils/createPath';
import ensureLocation from './utils/ensureLocation';
import createPath from './createPath';
import ensureLocation from './ensureLocation';

function noop() {}

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ensureLocationMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ActionTypes from './ActionTypes';
import ensureLocation from './utils/ensureLocation';
import ensureLocation from './ensureLocation';

export default function ensureLocationMiddleware() {
return (next) => (action) => {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export createHistoryEnhancer from './createHistoryEnhancer';
export createHistoryMiddleware from './createHistoryMiddleware';
export createLocationMiddleware from './createLocationMiddleware';
export createNavigationListenerMiddleware from './createNavigationListenerMiddleware';
export createPath from './createPath';
export createQueryMiddleware from './createQueryMiddleware';
export ensureLocation from './ensureLocation';
export ensureLocationMiddleware from './ensureLocationMiddleware';
export HashProtocol from './HashProtocol';
export locationReducer from './locationReducer';
Expand Down
2 changes: 1 addition & 1 deletion test/utils/createPath.test.js → test/createPath.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createPath from '../../src/utils/createPath';
import createPath from '../src/createPath';

describe('createPath', () => {
it('should create path using pathname, search, and hash', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ensureLocation from '../../src/utils/ensureLocation';
import ensureLocation from '../src/ensureLocation';

describe('ensureLocation', () => {
it('should preserve fully-defined location descriptor objects', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe('index', () => {
expect(farce.createHistoryMiddleware).to.exist();
expect(farce.createLocationMiddleware).to.exist();
expect(farce.createNavigationListenerMiddleware).to.exist();
expect(farce.createPath).to.exist();
expect(farce.createQueryMiddleware).to.exist();
expect(farce.ensureLocation).to.exist();
expect(farce.ensureLocationMiddleware).to.exist();
expect(farce.locationReducer).to.exist();
expect(farce.queryMiddleware).to.exist();
Expand Down
Loading