Skip to content

Commit

Permalink
run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdyn committed Feb 13, 2024
1 parent 6a2f48c commit e8b97d3
Show file tree
Hide file tree
Showing 16 changed files with 302 additions and 301 deletions.
71 changes: 32 additions & 39 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"react-hooks",
"simple-import-sort"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {},
"overrides": [
{
"files": [
"*.test.ts",
"*.test.tsx"
],
"rules": {
// Allow testing runtime errors to suppress TS errors
"@typescript-eslint/ban-ts-comment": "off"
}
}
],
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
}
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "react-hooks", "simple-import-sort"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {},
"overrides": [
{
"files": ["*.test.ts", "*.test.tsx"],
"rules": {
// Allow testing runtime errors to suppress TS errors
"@typescript-eslint/ban-ts-comment": "off"
}
}
],
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
}
}
16 changes: 8 additions & 8 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* {@type require('prettier').Config}
*/
module.exports = {
useTabs: false,
printWidth: 100,
singleQuote: true,
trailingComma: 'none',
bracketSameLine: false,
semi: true,
tabWidth: 2,
quoteProps: 'consistent'
useTabs: false,
printWidth: 100,
singleQuote: true,
trailingComma: 'none',
bracketSameLine: false,
semi: true,
tabWidth: 2,
quoteProps: 'consistent'
};
35 changes: 22 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@
2023-12-27

### Breaking changes

None

### Additional changes
* Fix buggy behavior where the reference to `useChannel` functions would be changing on every render. This would cause your useEffects to run even if there should be no change.

- Fix buggy behavior where the reference to `useChannel` functions would be changing on every render. This would cause your useEffects to run even if there should be no change.

# 0.0.1-alpha.6

2023-12-23

### Breaking changes

None

### Additional changes
* Fixed a bug where if you successfully connected to a channel, but then later on the topic supplied to `useChannel` had changed to `null` and then back to the valid topic, the `useChannel` hook functions like `push` would no longer be holding a valid reference to the channel. Now, the hook will successfully update the reference and the functions will work as if the channel topic never changed.
* Use the internel channel `ref` when using `useChannel`'s `leave`

- Fixed a bug where if you successfully connected to a channel, but then later on the topic supplied to `useChannel` had changed to `null` and then back to the valid topic, the `useChannel` hook functions like `push` would no longer be holding a valid reference to the channel. Now, the hook will successfully update the reference and the functions will work as if the channel topic never changed.
- Use the internel channel `ref` when using `useChannel`'s `leave`

# 0.0.1-alpha.5

2023-12-17

### Breaking changes
* The typescript type for `useChannel`'s `PushEvent` now aligns with the rest of the types

- The typescript type for `useChannel`'s `PushEvent` now aligns with the rest of the types

```jsx
type PushEvent = {
- type: string;
Expand All @@ -35,12 +42,14 @@ type PushEvent = {
```

### Additional changes
* Added rollup build tooling which should reduce bundle size slightly
* Phoenix.js is now marked as a peer dependency
* `useChannel` can now accept a short circuit operation to delay connecting to the channel until the condition is met.

```jsx
// Delay connecting until id is defined
const [channel] = useChannel(id && `room:${id}`)
```
* The `push` function type has been improved to catch more potential errors.

- Added rollup build tooling which should reduce bundle size slightly
- Phoenix.js is now marked as a peer dependency
- `useChannel` can now accept a short circuit operation to delay connecting to the channel until the condition is met.

```jsx
// Delay connecting until id is defined
const [channel] = useChannel(id && `room:${id}`);
```

- The `push` function type has been improved to catch more potential errors.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ Wrap the intended part of your application with a `PhoenixProvider`.
import { PhoenixProvider } from 'use-phoenix';

const Application = () => {
return <PhoenixProvider>...</PhoenixProvider>;
return <PhoenixProvider>...</PhoenixProvider>;
};
```

Passing a `url` and params to your `PhoenixProvder` will connect to your socket instantly **on mount**:

```tsx
return (
<PhoenixProvider
url="ws://localhost:4000/socket"
options={{
params: { token: 'xyz' }
}}
>
...
</PhoenixProvider>
<PhoenixProvider
url="ws://localhost:4000/socket"
options={{
params: { token: 'xyz' }
}}
>
...
</PhoenixProvider>
);
```

Expand All @@ -44,13 +44,13 @@ Later on when you would like to connect the socket:
import { usePhoenix } from 'use-phoenix';

const Component = () => {
const { socket, connect } = usePhoenix();
const { socket, connect } = usePhoenix();

useEffect(() => {
connect('ws://localhost:4000/socket', {
params: { token: 'xyz' }
});
}, [connect]);
useEffect(() => {
connect('ws://localhost:4000/socket', {
params: { token: 'xyz' }
});
}, [connect]);
};
```

Expand Down Expand Up @@ -135,7 +135,7 @@ Optionally, if you would rather capture the response in a callback you can (or b
```ts
const { data } = useEvent<JoinEvent>(channel, 'join', (data) => {
console.log(response);
console.log(response);
});
```
Expand Down Expand Up @@ -215,8 +215,8 @@ users[0].metas.lastSeen;
const [channel, { leave }] = useChannel('chat:lobby');

useEffect(() => {
return () => {
leave();
};
return () => {
leave();
};
}, [leave]);
```
40 changes: 20 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ import pkg from './package.json' assert { type: 'json' };
const isDev = process.env.BUILD !== 'production';

const cjs = {
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
plugins: !isDev && [terser()]
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
plugins: !isDev && [terser()]
};

const esm = {
file: pkg.module,
format: 'esm',
exports: 'named',
sourcemap: true
file: pkg.module,
format: 'esm',
exports: 'named',
sourcemap: true
};

const extensions = ['.js', '.ts', '.tsx', '.json'];

const plugins = [
typescript(),
resolve({ extensions }),
commonjs(),
babel({ exclude: 'node_modules/**', extensions }),
replace({
'preventAssignment': true,
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production')
})
resolve({ extensions }),
commonjs(),
babel({ exclude: 'node_modules/**', extensions }),
replace({
'preventAssignment': true,
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production')
})
].filter(Boolean);

export default {
input: 'src/index.ts',
output: isDev ? [esm] : [cjs, esm],
plugins,
external: Object.keys(pkg.peerDependencies)
input: 'src/index.ts',
output: isDev ? [esm] : [cjs, esm],
plugins,
external: Object.keys(pkg.peerDependencies)
};
Loading

0 comments on commit e8b97d3

Please sign in to comment.