Skip to content

Commit

Permalink
Cleanup (#19)
Browse files Browse the repository at this point in the history
- Moving from 'es' build to more standard 'esm' build
- Moving from mocha and sinon to jest
- Removing automated code coverage for simplicity (can just use jest for now)
- Upgrading to latest flow
- Upgrading to latest for all dependencies
  • Loading branch information
alexreardon authored Mar 21, 2018
1 parent a48573c commit f46d680
Show file tree
Hide file tree
Showing 32 changed files with 7,233 additions and 630 deletions.
23 changes: 21 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{
"presets": ["./.babelrc.js"]
}
"presets": [
"flow",
["env", { "modules": false, "loose": true }]
],
"comments": false,
"plugins": [
"transform-object-rest-spread"
],
"env": {
"cjs": {
"plugins": [
"transform-es2015-modules-commonjs"
]
},
"test": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
}
28 changes: 0 additions & 28 deletions .babelrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions .browserlistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ie >= 11
last 1 Edge version
last 1 Firefox version
last 1 Chrome version
last 1 Safari version
last 1 iOS version
last 1 Android version
last 1 ChromeAndroid version
14 changes: 0 additions & 14 deletions .codecov.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
],
"parser": "babel-eslint",
"plugins": [
"jest",
"flowtype"
],
"env": {
"node": true,
"browser": true,
"es6": true
"es6": true,
"jest/globals": true
},
// custom rules
"rules": {
Expand Down Expand Up @@ -136,6 +138,8 @@
"indent": [
"error",
2
]
],
// Require // @flow at the top of files
"flowtype/require-valid-file-annotation": ["error", "always", { "annotationStyle": "line" }]
}
}
14 changes: 2 additions & 12 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
[ignore]

[include]

[libs]

[options]

# Opting in to 'Strict Checking of Function Call Arity'
# https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/
experimental.strict_call_arity=true

# Provides a way to suppress flow errors in the following line.
# Example: // $FlowFixMe: This following line is borked because of reasons.
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
suppress_comment= \\(.\\|\n\\)*\\$ExpectEror
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ node_modules/

# generated files
lib/
es/
.nyc_output/
coverage.lcov
coverage/
esm/

# editors
.idea
.vscode
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: node_js
cache: yarn
node_js:
- "6.9"
- '8.4'
script:
- "yarn run test"
after_success:
- "yarn run coverage"
- yarn run validate
- yarn run test
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A memoization library which only remembers the latest invocation

[![Build Status](https://travis-ci.org/alexreardon/memoize-one.svg?branch=master)](https://travis-ci.org/alexreardon/memoize-one) [![codecov](https://codecov.io/gh/alexreardon/memoize-one/branch/master/graph/badge.svg)](https://codecov.io/gh/alexreardon/memoize-one) [![dependencies](https://david-dm.org/alexreardon/memoize-one.svg)](https://david-dm.org/alexreardon/memoize-one) [![SemVer](https://img.shields.io/badge/SemVer-2.0.0-brightgreen.svg)](http://semver.org/spec/v2.0.0.html)
[![Build Status](https://travis-ci.org/alexreardon/memoize-one.svg?branch=master)](https://travis-ci.org/alexreardon/memoize-one) [![dependencies](https://david-dm.org/alexreardon/memoize-one.svg)](https://david-dm.org/alexreardon/memoize-one) [![SemVer](https://img.shields.io/badge/SemVer-2.0.0-brightgreen.svg)](http://semver.org/spec/v2.0.0.html)

## Rationale

Expand Down Expand Up @@ -45,6 +45,7 @@ memoizedAdd(1, 2); // 3
[Play with this example](http://www.webpackbin.com/NkCiYkz_M)

### Custom equality function

You can also pass in a custom function for checking the equality of two items.

```js
Expand All @@ -66,15 +67,48 @@ const result4 = customMemoization({foo: 'bar'});

result3 === result4 // true - arguments are deep equal
```

[Play with this example](http://www.webpackbin.com/NJW-tJMdf)

#### Type signature
#### Equality function type signature

Here is the expected [flow](http://flowtype.org) type signature for a custom equality function:

```js
type EqualityFn = (a: any, b: any) => boolean;
```

### Dynamic properties

The result function will have the same [`.length` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length) as the provided function.

```js
const add = (a, b) => a + b;
const memoizedAdd = memoizeOne(add);

memoizedAdd.length === 2; // true
```

- For debug purposes we add a [`.name` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) to the result function. If provided function has a name then the name will be `memoized_${yourFunction.name}`. Otherwise it will be `memoized_fn`. This assists in debugging memoized functions.

```js
// function has a name
const add = (a, b) => a + b;

// the original name is 'add'
add.name === 'add'; // true

// our new memoizedAdd function has a prefixed name
const memoizedAdd = memoizeOne(add);
memoizedAdd.name === 'memoized_add'; // true
```

```js
// function does not have a name
const memoizedInline = memoizeOne((a, b) => a + b);
memoizedInline.name === 'memoized_fn';
```

## Installation

```bash
Expand Down Expand Up @@ -141,12 +175,15 @@ Generally this will be of no impact if you are not explicity controlling the `th
## Performance :rocket:

### Tiny

`memoizeOne` is super lightweight at `457 bytes` minified and `299 bytes` gzipped. (`1kb` = `1000 bytes`)

### Extremely fast

`memoizeOne` performs better or on par with than other popular memoization libraries for the purpose of remembering the latest invocation.

**Results**

- [simple arguments](https://www.measurethat.net/Benchmarks/ShowResult/4452)
- [complex arguments](https://www.measurethat.net/Benchmarks/ShowResult/4488)

Expand All @@ -155,7 +192,7 @@ The comparisions are not exhaustive and are primiarly to show that `memoizeOne`
## Code health :thumbsup:

- Tested with all built in [JavaScript types](https://github.com/getify/You-Dont-Know-JS/blob/master/types%20%26%20grammar/ch1.md).
- [100% code coverage](https://codecov.io/gh/alexreardon/memoize-one).
- 100% code coverage
- [Continuous integration](https://travis-ci.org/alexreardon/memoize-one) to run tests and type checks.
- [`Flow` types](http://flowtype.org) for safer internal execution and external consumption. Also allows for editor autocompletion.
- Follows [Semantic versioning (2.0)](http://semver.org/) for safer consumption.
Expand Down
108 changes: 108 additions & 0 deletions flow-typed/npm/babel-cli_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// flow-typed signature: d8044ea585ac81bc8bde751918bbb405
// flow-typed version: <<STUB>>/babel-cli_v6.26.0/flow_v0.68.0

/**
* This is an autogenerated libdef stub for:
*
* 'babel-cli'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/

declare module 'babel-cli' {
declare module.exports: any;
}

/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'babel-cli/bin/babel-doctor' {
declare module.exports: any;
}

declare module 'babel-cli/bin/babel-external-helpers' {
declare module.exports: any;
}

declare module 'babel-cli/bin/babel-node' {
declare module.exports: any;
}

declare module 'babel-cli/bin/babel' {
declare module.exports: any;
}

declare module 'babel-cli/lib/_babel-node' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel-external-helpers' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel-node' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel/dir' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel/file' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel/index' {
declare module.exports: any;
}

declare module 'babel-cli/lib/babel/util' {
declare module.exports: any;
}

// Filename aliases
declare module 'babel-cli/bin/babel-doctor.js' {
declare module.exports: $Exports<'babel-cli/bin/babel-doctor'>;
}
declare module 'babel-cli/bin/babel-external-helpers.js' {
declare module.exports: $Exports<'babel-cli/bin/babel-external-helpers'>;
}
declare module 'babel-cli/bin/babel-node.js' {
declare module.exports: $Exports<'babel-cli/bin/babel-node'>;
}
declare module 'babel-cli/bin/babel.js' {
declare module.exports: $Exports<'babel-cli/bin/babel'>;
}
declare module 'babel-cli/index' {
declare module.exports: $Exports<'babel-cli'>;
}
declare module 'babel-cli/index.js' {
declare module.exports: $Exports<'babel-cli'>;
}
declare module 'babel-cli/lib/_babel-node.js' {
declare module.exports: $Exports<'babel-cli/lib/_babel-node'>;
}
declare module 'babel-cli/lib/babel-external-helpers.js' {
declare module.exports: $Exports<'babel-cli/lib/babel-external-helpers'>;
}
declare module 'babel-cli/lib/babel-node.js' {
declare module.exports: $Exports<'babel-cli/lib/babel-node'>;
}
declare module 'babel-cli/lib/babel/dir.js' {
declare module.exports: $Exports<'babel-cli/lib/babel/dir'>;
}
declare module 'babel-cli/lib/babel/file.js' {
declare module.exports: $Exports<'babel-cli/lib/babel/file'>;
}
declare module 'babel-cli/lib/babel/index.js' {
declare module.exports: $Exports<'babel-cli/lib/babel/index'>;
}
declare module 'babel-cli/lib/babel/util.js' {
declare module.exports: $Exports<'babel-cli/lib/babel/util'>;
}
Loading

0 comments on commit f46d680

Please sign in to comment.