Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

Commit f86602b

Browse files
committed
Require Node.js 12 and move to ESM
1 parent 061d302 commit f86602b

10 files changed

+40
-55
lines changed

.github/funding.yml

-3
This file was deleted.

.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
16-
- 8
1716
steps:
1817
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
18+
- uses: actions/setup-node@v2
2019
with:
2120
node-version: ${{ matrix.node-version }}
2221
- run: npm install

browser-env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const browserEnv = require('browser-env');
1+
import browserEnv from 'browser-env';
22

33
browserEnv();

index.d.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React from 'react';
1111
import {render} from 'react-dom';
1212
import {Provider} from 'unstated';
1313
import UNSTATED from 'unstated-debug';
14-
import App from './components/App';
14+
import App from './components/App.js';
1515
1616
UNSTATED.logStateChanges = false;
1717
@@ -48,16 +48,12 @@ declare const UNSTATED: {
4848
/**
4949
Your containers.
5050
*/
51-
containers: {
52-
[containerName: string]: Container<{[stateName: string]: unknown}>;
53-
};
51+
containers: Record<string, Container<Record<string, unknown>>>;
5452

5553
/**
5654
All of the state values.
5755
*/
58-
states: {
59-
[containerName: string]: {[stateName: string]: unknown};
60-
};
56+
states: Record<string, Record<string, unknown>>;
6157

6258
/**
6359
Logs the current state of your containers.

index.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
'use strict';
2-
const {detailedDiff} = require('deep-object-diff');
3-
const {__SUPER_SECRET_CONTAINER_DEBUG_HOOK__} = require('unstated');
1+
import {detailedDiff} from 'deep-object-diff';
2+
import {__SUPER_SECRET_CONTAINER_DEBUG_HOOK__} from 'unstated';
43

54
const UNSTATED = {
65
isEnabled: true,
76
isCollapsed: false,
87
logStateChanges: true,
98
containers: {},
109
get states() {
11-
const ret = {};
12-
for (const [key, value] of Object.entries(this.containers)) {
13-
ret[key] = value.state;
14-
}
15-
16-
return ret;
10+
return Object.fromEntries(
11+
Object.entries(this.containers).map(([key, value]) => [key, value.state])
12+
);
1713
},
1814
logState() {
1915
for (const [key, value] of Object.entries(this.containers)) {
@@ -31,20 +27,20 @@ __SUPER_SECRET_CONTAINER_DEBUG_HOOK__(container => {
3127

3228
UNSTATED.containers[name] = container;
3329

34-
let prevState = container.state;
30+
let previousState = container.state;
3531

3632
container.subscribe(() => {
3733
if (!(UNSTATED.isEnabled && UNSTATED.logStateChanges)) {
3834
return;
3935
}
4036

4137
const {state} = container;
42-
const diff = detailedDiff(prevState, state);
38+
const diff = detailedDiff(previousState, state);
4339

4440
const group = UNSTATED.isCollapsed ? console.groupCollapsed : console.group;
4541
group(name);
4642

47-
const hasChanges = obj => Object.keys(obj).length > 0;
43+
const hasChanges = object => Object.keys(object).length > 0;
4844

4945
if (hasChanges(diff.added)) {
5046
console.log('Added\n', diff.added);
@@ -59,15 +55,16 @@ __SUPER_SECRET_CONTAINER_DEBUG_HOOK__(container => {
5955
}
6056

6157
console.log('New state\n', state);
62-
console.log('Old state\n', prevState);
58+
console.log('Old state\n', previousState);
6359

6460
console.groupEnd(name);
6561

66-
prevState = state;
62+
previousState = state;
6763
});
6864
});
65+
6966
if (typeof window !== 'undefined') {
7067
window.UNSTATED = UNSTATED;
7168
}
7269

73-
module.exports = UNSTATED;
70+
export default UNSTATED;

index.test-d.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import {expectType} from 'tsd';
22
import {Container} from 'unstated';
3-
import UNSTATED from '.';
3+
import UNSTATED from './index.js';
44

55
expectType<boolean>(UNSTATED.isEnabled);
66
expectType<boolean>(UNSTATED.logStateChanges);
77

8-
expectType<{
9-
[containerName: string]: Container<{[stateName: string]: unknown}>;
10-
}>(UNSTATED.containers);
8+
expectType<Record<string, Container<Record<string, unknown>>>>(UNSTATED.containers);
119

1210
expectType<() => void>(UNSTATED.logState);
13-
expectType<void>(UNSTATED.logState());
1411

15-
expectType<{[containerName: string]: {[stateName: string]: unknown }}>(
12+
expectType<Record<string, Record<string, unknown>>>(
1613
UNSTATED.states
1714
);

license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Debug your Unstated containers with ease",
55
"license": "MIT",
66
"repository": "sindresorhus/unstated-debug",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -36,16 +39,16 @@
3639
"deep-object-diff": "^1.1.0"
3740
},
3841
"devDependencies": {
39-
"@types/react": "^16.9.4",
40-
"ava": "^2.4.0",
41-
"browser-env": "^3.2.5",
42-
"react": "^16.3.0",
43-
"tsd": "^0.9.0",
44-
"unstated": "^2.0.2",
45-
"xo": "^0.25.0"
42+
"@types/react": "^17.0.4",
43+
"ava": "^3.15.0",
44+
"browser-env": "^3.3.0",
45+
"react": "^16.0.0",
46+
"tsd": "^0.14.0",
47+
"unstated": "^2.1.1",
48+
"xo": "^0.39.1"
4649
},
4750
"peerDependencies": {
48-
"unstated": "^2.0.2"
51+
"unstated": "^2.1.1"
4952
},
5053
"xo": {
5154
"envs": [

readme.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
<br>
66
<img src="screenshot.png" width="1145">
77

8-
98
## Install
109

1110
```
1211
$ npm install unstated-debug
1312
```
1413

15-
1614
## Setup
1715

1816
In the root of your app, import `unstated-debug`:
@@ -22,7 +20,7 @@ import React from 'react';
2220
import {render} from 'react-dom';
2321
import {Provider} from 'unstated';
2422
import UNSTATED from 'unstated-debug';
25-
import App from './components/App';
23+
import App from './components/App.js';
2624

2725
UNSTATED.logStateChanges = false;
2826

@@ -34,7 +32,6 @@ render(
3432
);
3533
```
3634

37-
3835
## Usage
3936

4037
When enabled, it exposes a global object `UNSTATED` which you can use in DevTools to explore the containers and their state.
@@ -50,14 +47,13 @@ The object contains the following properties:
5047
- `states` - The state objects of your containers.
5148
- `logState()` - Logs the current state of your containers.
5249

53-
5450
## API
5551

5652
### UNSTATED
5753

5854
##### isEnabled
5955

60-
Type: `boolean`<br>
56+
Type: `boolean`\
6157
Default: `true`
6258

6359
Toggle debugging.
@@ -66,7 +62,7 @@ For example, if you use this in an Electron app, you could pass it [`is.developm
6662

6763
##### logStateChanges
6864

69-
Type: `boolean`<br>
65+
Type: `boolean`\
7066
Default: `true`
7167

7268
Logs a diff for each state change to the containers. This gives you a live insight into state changes in your app.

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22
import {Container} from 'unstated';
3-
import m from '.';
3+
import UNSTATED from './index.js';
44

55
class FixtureContainer extends Container {
66
constructor() {
@@ -19,7 +19,7 @@ test('main', t => {
1919
});
2020

2121
test('exposes window global', t => {
22-
t.is(m, window.UNSTATED);
22+
t.is(UNSTATED, window.UNSTATED);
2323
t.is(typeof window.UNSTATED, 'object');
2424
t.true(window.UNSTATED.containers.FixtureContainer.state.foo);
2525
});

0 commit comments

Comments
 (0)