Skip to content

Commit

Permalink
[BREAKING] ES6 tree-shaking by only using named exports and preservin…
Browse files Browse the repository at this point in the history
…g modules (#1888)

Co-authored-by: Taylor Clay <tclay@atlassian.com>
Co-authored-by: Julien Deniau <julien.deniau@gmail.com>
  • Loading branch information
3 people committed Aug 24, 2023
1 parent c25fac2 commit 8dffce4
Show file tree
Hide file tree
Showing 7 changed files with 1,288 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- 5.x
pull_request:
branches:
- main
- 5.x

jobs:
lint:
Expand Down Expand Up @@ -64,6 +66,7 @@ jobs:
- run: npm ci
- run: npm run build
- run: npm run unit-test
- run: npx size-limit
- run: npm run check-git-clean

website:
Expand Down
29 changes: 28 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,33 @@ Dates are formatted as YYYY-MM-DD.

### Changed

### Improve TypeScript definition for `Map`
### [Minor BC break] Reducing file size / tree shaking

Immutable does not export a default object containing all it's API anymore.
It changes the output of your JS file if you use a bundler that supports tree-shaking (all modern bundler do).
As a drawback, you can not `immport Immutable` directly:

```diff
- import Immutable from 'immutable';
+ import { List, Map } from 'immutable';

- const l = Immutable.List([Immutable.Map({ a: 'A' })]);
+ const l = List([Map({ a: 'A' })]);
```

If you want the non-recommanded, but shorter migration path, you can do this:

```diff
- import Immutable from 'immutable';
+ import * as Immutable from 'immutable';

const l = Immutable.List([Immutable.Map({ a: 'A' })]);
```

### [TypeScript Break] Improve TypeScript definition for `Map`

> If you do use TypeScript, then this change does not impact you : no runtime change here.
> But if you use Map with TypeScript, this is a HUGE change !
Imagine the following code

Expand Down Expand Up @@ -121,6 +147,7 @@ For now, only `get`, `getIn`, `set`, `update`, `delete` and `remove` methods are

## [4.1.0] - 2022-05-23

- [BREAKING] The ES6 bundle no longer exposes a default export, which allows bundlers to apply tree-shaking. [#1888](https://github.com/immutable-js/immutable-js/pull/1888) by [bdurrer](https://github.com/bdurrer)
- Accept Symbol as Map key. [#1859](https://github.com/immutable-js/immutable-js/pull/1859) by [jdeniau](https://github.com/jdeniau)
- Optimize contructors without arguments [#1887](https://github.com/immutable-js/immutable-js/pull/1887) by [marianoguerra](https://github.com/marianoguerra)
- Fix Flow removeIn types [#1902](https://github.com/immutable-js/immutable-js/pull/1902) by [nifgraup](https://github.com/nifgraup)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ via relative path to the type definitions at the top of your file.

```js
///<reference path='./node_modules/immutable/dist/immutable.d.ts'/>
import Immutable from 'immutable';
var map1: Immutable.Map<string, number>;
map1 = Immutable.Map({ a: 1, b: 2, c: 3 });
import { Map } from 'immutable';
var map1: Map<string, number>;
map1 = Map({ a: 1, b: 2, c: 3 });
var map2 = map1.set('b', 50);
map1.get('b'); // 2
map2.get('b'); // 50
Expand Down

0 comments on commit 8dffce4

Please sign in to comment.