Skip to content

Commit

Permalink
Fixes and types improvements (#36)
Browse files Browse the repository at this point in the history
Fixes and types improvements
  • Loading branch information
planttheidea authored Jul 9, 2019
2 parents a553de4 + 98fb3fa commit d3f9cdb
Show file tree
Hide file tree
Showing 18 changed files with 3,756 additions and 4,075 deletions.
9 changes: 9 additions & 0 deletions .release-it.beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"github": {
"release": true
},
"npm": {
"tag": "next"
},
"preReleaseId": "beta"
}
6 changes: 6 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"github": {
"release": true,
"tagName": "v${version}"
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Yes, the irony is not lost on me. :)

## 2.1.1

- Fix issue where `getOwnPropertySymbols` was expected to always be supported when `Object.assign` was natively supported
- Greatly improve typings of handlers

## 2.1.0

- Add [not](README.md#not) and [notWith](README.md#notwith) methods
Expand Down
80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
# unchanged

A tiny (~2.0kB minified+gzipped), [fast](https://github.com/planttheidea/unchanged/blob/master/benchmark_results.csv), unopinionated handler for updating JS objects and arrays immutably.
A tiny (~2.1kB minified+gzipped), [fast](https://github.com/planttheidea/unchanged/blob/master/benchmark_results.csv), unopinionated handler for updating JS objects and arrays immutably.

Supports nested key paths via path arrays or [dotty syntax](https://github.com/planttheidea/pathington), and all methods are curriable (with placeholder support) for composability. Can be a drop-in replacement for the `lodash/fp` methods `get`, `set`, `merge`, and `omit` with a 90% smaller footprint.

## Table of contents

- [Usage](#usage)
- [Types](#types)
- [Standard methods](#standard-methods)
- [get](#get)
- [getOr](#getor)
- [set](#set)
- [remove](#remove)
- [has](#has)
- [is](#is)
- [not](#not)
- [add](#add)
- [merge](#merge)
- [assign](#assign)
- [call](#call)
- [Transform methods](#transform-methods)
- [getWith](#getwith)
- [getWithOr](#getwithor)
- [setWith](#setwith)
- [removeWith](#removewith)
- [hasWith](#haswith)
- [isWith](#iswith)
- [notWith](#notwith)
- [addWith](#addwith)
- [mergeWith](#mergewith)
- [assignWith](#assignwith)
- [callWith](#callwith)
- [Additional objects](#additional-objects)
- [\_\_](#__)
- [Differences from other libraries](#differences-from-other-libraries)
- [lodash](#lodash)
- [ramda](#ramda)
- [Other immutability libraries](#other-immutability-libraries)
- [Browser support](#browser-support)
- [Development](#development)
- [unchanged](#unchanged)
- [Table of contents](#Table-of-contents)
- [Usage](#Usage)
- [Types](#Types)
- [Standard methods](#Standard-methods)
- [get](#get)
- [getOr](#getOr)
- [set](#set)
- [remove](#remove)
- [has](#has)
- [is](#is)
- [not](#not)
- [add](#add)
- [merge](#merge)
- [assign](#assign)
- [call](#call)
- [Transform methods](#Transform-methods)
- [getWith](#getWith)
- [getWithOr](#getWithOr)
- [setWith](#setWith)
- [removeWith](#removeWith)
- [hasWith](#hasWith)
- [isWith](#isWith)
- [notWith](#notWith)
- [addWith](#addWith)
- [mergeWith](#mergeWith)
- [assignWith](#assignWith)
- [callWith](#callWith)
- [Additional objects](#Additional-objects)
- [\_\_](#)
- [Differences from other libraries](#Differences-from-other-libraries)
- [lodash](#lodash)
- [ramda](#ramda)
- [Other immutability libraries](#Other-immutability-libraries)
- [Browser support](#Browser-support)
- [Development](#Development)

## Usage

Expand Down Expand Up @@ -102,7 +104,7 @@ This library is both written in, and provided with, types by TypeScript. The int
// the path used to compute nested locations
type Path = (number | string)[] | number | string;
// the callback used in transform methods
type withHandler = (value: any, ...extraParams: any[]) => any;
type WithHandler = (value: any, ...extraParams: any[]) => any;
// the generic object that is computed upon, either an array or object
interface Unchangeable {
[key: string]: any;
Expand All @@ -113,7 +115,7 @@ interface Unchangeable {
Notice in the `Unchangeable` interface, there is no reference to symbols. That is because to date, TypeScript does not support Symbols as an index type. If you need to use symbols as object keys, the best workaround I've found is to typecast when it complains:

```typescript
const symbolKey: string = (Symbol("key") as unknown) as string;
const symbolKey = (Symbol("key") as unknown) as string;

const object: { [symbolKey]: string } = {
[symbolKey]: "bar"
Expand Down Expand Up @@ -1022,7 +1024,7 @@ setFooOnThing('bar');

[`lodash/fp`](https://lodash.com/) (the functional programming implementation of `lodash`) is identical in implementation to `unchanged`'s methods, just with a _10.5x_ larger footprint. These methods should map directly:

- _lodash_ => _unchanged_
- _lodash/fp_ => _unchanged_
- `curry.placeholder` => `__`
- `get` => `get`
- `getOr` => `getOr`
Expand All @@ -1042,7 +1044,7 @@ setFooOnThing('bar');
- `omit` => `remove`
- `assocPath` => `set`

Another difference is that the `ramda` methods that clone objects (`assocPath`, for example) only work with objects; arrays are implicitly converted into objects, which can make updating collections challenging.
Another difference is that the `ramda` methods that clone (`assocPath`, for example) only work with objects; arrays are implicitly converted into objects, which can make updating collections challenging.

The last main difference is the way that objects are copied, example:

Expand Down
Loading

0 comments on commit d3f9cdb

Please sign in to comment.