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

Commit 813cbe1

Browse files
committed
Improve TypeScript definition
1 parent eabcd4e commit 813cbe1

6 files changed

+61
-34
lines changed

.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
4+
- '10'
35
- '8'

index.d.ts

+47-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,68 @@
1-
import { Container } from "unstated";
1+
import {Container} from 'unstated';
22

3+
/**
4+
When enabled, it exposes a global object `UNSTATED` which you can use in DevTools to explore the containers and their state.
5+
6+
In the root of your app, import `unstated-debug`:
7+
8+
@example
9+
```
10+
import React from 'react';
11+
import {render} from 'react-dom';
12+
import {Provider} from 'unstated';
13+
import UNSTATED from 'unstated-debug';
14+
import App from './components/App';
15+
16+
UNSTATED.logStateChanges = false;
17+
18+
render(
19+
<Provider>
20+
<App/>
21+
</Provider>,
22+
document.querySelector('#root')
23+
);
24+
```
25+
*/
326
declare const UNSTATED: {
427
/**
5-
An object containing the project's containers.
28+
Whether the debugger should be enabled or not.
29+
30+
@default true
631
*/
7-
containers: {
8-
[containerName: string]: Container<{ [stateName: string]: unknown }>;
9-
};
32+
isEnabled: boolean;
1033

1134
/**
12-
Whether the debugger should be enabled or not.
35+
Whether state changes should be logged to the console.
36+
37+
@default true
1338
*/
14-
isEnabled: boolean;
39+
logStateChanges: boolean;
1540

1641
/**
17-
Function that logs out the current state.
42+
Whether logs should be collapsed.
43+
44+
@default false
1845
*/
19-
logState: () => void;
46+
isCollapsed: boolean;
2047

2148
/**
22-
Boolean value that represents whether state changes should be logged to the
23-
console.
49+
Your containers.
2450
*/
25-
logStateChanges: boolean;
51+
containers: {
52+
[containerName: string]: Container<{[stateName: string]: unknown}>;
53+
};
2654

2755
/**
28-
An object containing all of the state values.
56+
All of the state values.
2957
*/
3058
states: {
31-
[containerName: string]: { [stateName: string]: unknown };
59+
[containerName: string]: {[stateName: string]: unknown};
3260
};
61+
62+
/**
63+
Logs the current state of your containers.
64+
*/
65+
logState: () => void;
3366
};
3467

3568
export default UNSTATED;

index.test-d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { expectType } from "tsd-check";
2-
import UNSTATED from "./index";
3-
import { Container } from "unstated";
1+
import {expectType} from 'tsd';
2+
import {Container} from 'unstated';
3+
import UNSTATED from '.';
44

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

88
expectType<{
9-
[containerName: string]: Container<{ [stateName: string]: unknown }>;
9+
[containerName: string]: Container<{[stateName: string]: unknown}>;
1010
}>(UNSTATED.containers);
1111

1212
expectType<() => void>(UNSTATED.logState);
1313
expectType<void>(UNSTATED.logState());
1414

15-
expectType<{ [containerName: string]: { [stateName: string]: unknown } }>(
15+
expectType<{[containerName: string]: {[stateName: string]: unknown }}>(
1616
UNSTATED.states
1717
);

package.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava && tsd-check"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
@@ -36,12 +36,13 @@
3636
"deep-object-diff": "^1.1.0"
3737
},
3838
"devDependencies": {
39-
"ava": "*",
39+
"@types/react": "^16.9.4",
40+
"ava": "^2.4.0",
4041
"browser-env": "^3.2.5",
4142
"react": "^16.3.0",
42-
"tsd-check": "^0.6.0",
43+
"tsd": "^0.9.0",
4344
"unstated": "^2.0.2",
44-
"xo": "*"
45+
"xo": "^0.25.0"
4546
},
4647
"peerDependencies": {
4748
"unstated": "^2.0.2"
@@ -50,9 +51,6 @@
5051
"envs": [
5152
"node",
5253
"browser"
53-
],
54-
"ignores": [
55-
"*.ts"
5654
]
5755
},
5856
"ava": {

readme.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The object contains the following properties:
4545

4646
- `isEnabled` - Same as the below option, but you can change it after init.
4747
- `logStateChanges` - Same as the below option, but you can change it after init.
48-
- `isCollapsed` - Collapse logs by default.
48+
- `isCollapsed` - Collapse logs. (Default: false)
4949
- `containers` - Your containers.
5050
- `states` - The state objects of your containers.
5151
- `logState()` - Logs the current state of your containers.
@@ -72,8 +72,3 @@ Default: `true`
7272
Logs a diff for each state change to the containers. This gives you a live insight into state changes in your app.
7373

7474
<img src="screenshot-diff.png" width="400">
75-
76-
77-
## License
78-
79-
MIT © [Sindre Sorhus](https://sindresorhus.com)

0 commit comments

Comments
 (0)