Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 31, 2024
1 parent 49c318a commit 34e9e1d
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 40 deletions.
4 changes: 2 additions & 2 deletions benchmark/static/static.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ function App() {
id: number;
}>
>([]);
const itemCountRef = React.useRef(0);
const itemCountReference = React.useRef(0);

React.useEffect(() => {
let timer: NodeJS.Timeout | undefined;

const run = () => {
if (itemCountRef.current++ > 1000) {
if (itemCountReference.current++ > 1000) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/jest/jest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type State = {
};

class Jest extends React.Component<Record<string, unknown>, State> {
constructor(props: Record<string, unknown>) {
super(props);
constructor(properties: Record<string, unknown>) {
super(properties);

this.state = {
startTime: Date.now(),
Expand Down
4 changes: 2 additions & 2 deletions examples/jest/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import {Box, Text} from '../../src/index.js';

type Props = {
type Properties = {
readonly isFinished: boolean;
readonly passed: number;
readonly failed: number;
readonly time: string;
};

function Summary({isFinished, passed, failed, time}: Props) {
function Summary({isFinished, passed, failed, time}: Properties) {
return (
<Box flexDirection="column" marginTop={1}>
<Box>
Expand Down
4 changes: 2 additions & 2 deletions examples/jest/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const getBackgroundForStatus = (status: string): string | undefined => {
}
};

type Props = {
type Properties = {
readonly status: string;
readonly path: string;
};

function Test({status, path}: Props) {
function Test({status, path}: Properties) {
return (
<Box>
<Text color="black" backgroundColor={getBackgroundForStatus(status)}>
Expand Down
1 change: 1 addition & 0 deletions examples/subprocess-output/subprocess-output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function SubprocessOutput() {
'examples/jest',
]);

// eslint-disable-next-line @typescript-eslint/ban-types
subProcess.stdout.on('data', (newOutput: Buffer) => {
const lines = stripAnsi(newOutput.toString('utf8')).split('\n');
setOutput(lines.slice(-5).join('\n'));
Expand Down
4 changes: 2 additions & 2 deletions examples/use-focus-with-id/use-focus-with-id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ function Focus() {
);
}

type ItemProps = {
type ItemProperties = {
readonly id: number;
readonly label: string;
};

function Item({label, id}: ItemProps) {
function Item({label, id}: ItemProperties) {
const {isFocused} = useFocus({id});

return (
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
],
"dependencies": {
"@alcalzone/ansi-tokenize": "^0.1.3",
"ansi-escapes": "^6.0.0",
"ansi-escapes": "^7.0.0",
"ansi-styles": "^6.2.1",
"auto-bind": "^5.0.1",
"chalk": "^5.3.0",
Expand Down Expand Up @@ -77,9 +77,9 @@
"@types/node": "^20.10.4",
"@types/react": "^18.2.43",
"@types/react-reconciler": "^0.28.2",
"@types/scheduler": "^0.16.8",
"@types/scheduler": "^0.23.0",
"@types/signal-exit": "^3.0.0",
"@types/sinon": "^10.0.20",
"@types/sinon": "^17.0.3",
"@types/stack-utils": "^2.0.2",
"@types/ws": "^8.5.10",
"@vdemedes/prettier-config": "^2.0.1",
Expand All @@ -88,18 +88,18 @@
"delay": "^6.0.0",
"eslint-config-xo-react": "0.27.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-hooks": "^4.6.2",
"ms": "^2.1.3",
"node-pty": "^1.0.0",
"p-queue": "^8.0.0",
"prettier": "^3.1.1",
"react": "^18.0.0",
"react-devtools-core": "^5.0.0",
"sinon": "^17.0.0",
"sinon": "^18.0.0",
"strip-ansi": "^7.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"xo": "^0.56.0"
"xo": "^0.58.0"
},
"peerDependencies": {
"@types/react": ">=18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export default class App extends PureComponent<Props, State> {
focusNext = (): void => {
this.setState(previousState => {
const firstFocusableId = previousState.focusables.find(
focusable => focusable.isActive
focusable => focusable.isActive,
)?.id;
const nextFocusableId = this.findNextFocusable(previousState);

Expand All @@ -264,7 +264,7 @@ export default class App extends PureComponent<Props, State> {
focusPrevious = (): void => {
this.setState(previousState => {
const lastFocusableId = previousState.focusables.findLast(
focusable => focusable.isActive
focusable => focusable.isActive,
)?.id;
const previousFocusableId = this.findPreviousFocusable(previousState);

Expand Down
12 changes: 3 additions & 9 deletions src/devtools-window-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import ws from 'ws';
const customGlobal = global as any;

// These things must exist before importing `react-devtools-core`
if (!customGlobal.WebSocket) {
customGlobal.WebSocket = ws;
}
customGlobal.WebSocket ||= ws;

if (!customGlobal.window) {
customGlobal.window = global;
}
customGlobal.window ||= global;

if (!customGlobal.self) {
customGlobal.self = global;
}
customGlobal.self ||= global;

// Filter out Ink's internal components from devtools for a cleaner view.
// Also, ince `react-devtools-shared` package isn't published on npm, we can't
Expand Down
10 changes: 4 additions & 6 deletions src/ink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,10 @@ export default class Ink {
}

async waitUntilExit(): Promise<void> {
if (!this.exitPromise) {
this.exitPromise = new Promise((resolve, reject) => {
this.resolveExitPromise = resolve;
this.rejectExitPromise = reject;
});
}
this.exitPromise ||= new Promise((resolve, reject) => {
this.resolveExitPromise = resolve;
this.rejectExitPromise = reject;
});

return this.exitPromise;
}
Expand Down
2 changes: 1 addition & 1 deletion src/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const diff = (before: AnyObject, after: AnyObject): AnyObject | undefined => {
let isChanged = false;

for (const key of Object.keys(before)) {
const isDeleted = after ? !Object.hasOwnProperty.call(after, key) : true;
const isDeleted = after ? !Object.hasOwn(after, key) : true;

if (isDeleted) {
changed[key] = undefined;
Expand Down
12 changes: 6 additions & 6 deletions test/focus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,14 @@ test('focuses first non-disabled component', async t => {
render(<Test autoFocus disableFirst disableSecond />, {
stdout,
stdin,
debug: true
debug: true,
});

await delay(100);

t.is(
(stdout.write as any).lastCall.args[0],
['First', 'Second', 'Third βœ”'].join('\n')
['First', 'Second', 'Third βœ”'].join('\n'),
);
});

Expand All @@ -472,7 +472,7 @@ test('skips disabled elements when wrapping around', async t => {
render(<Test autoFocus disableFirst />, {
stdout,
stdin,
debug: true
debug: true,
});

await delay(100);
Expand All @@ -483,7 +483,7 @@ test('skips disabled elements when wrapping around', async t => {

t.is(
(stdout.write as any).lastCall.args[0],
['First', 'Second βœ”', 'Third'].join('\n')
['First', 'Second βœ”', 'Third'].join('\n'),
);
});

Expand All @@ -493,7 +493,7 @@ test('skips disabled elements when wrapping around from the front', async t => {
render(<Test autoFocus disableThird />, {
stdout,
stdin,
debug: true
debug: true,
});

await delay(100);
Expand All @@ -502,6 +502,6 @@ test('skips disabled elements when wrapping around from the front', async t => {

t.is(
(stdout.write as any).lastCall.args[0],
['First', 'Second βœ”', 'Third'].join('\n')
['First', 'Second βœ”', 'Third'].join('\n'),
);
});

0 comments on commit 34e9e1d

Please sign in to comment.