Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/red-pandas-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'electron-trpc': patch
---

Fix transforms not running for subscriptions.

pr: 125
49 changes: 0 additions & 49 deletions CHANGELOG.md

This file was deleted.

35 changes: 35 additions & 0 deletions examples/basic-react-superjson/electron/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import z from 'zod';
import { initTRPC } from '@trpc/server';
import { observable } from '@trpc/server/observable';
import { EventEmitter } from 'events';
import superjson from 'superjson';

const ee = new EventEmitter();

const t = initTRPC.create({ isServer: true, transformer: superjson });

export const router = t.router({
greeting: t.procedure.input(z.object({ name: z.string() })).query((req) => {
const { input } = req;

ee.emit('greeting', `Greeted ${input.name}`);
return {
text: `Hello ${input.name}` as const,
};
}),
subscription: t.procedure.subscription(() => {
return observable((emit) => {
function onGreet(text: string) {
emit.next({ text });
}

ee.on('greeting', onGreet);

return () => {
ee.off('greeting', onGreet);
};
});
}),
});

export type AppRouter = typeof router;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "examples/basic",
"description": "Electron support for tRPC",
"name": "examples/basic-react-superjson",
"version": "0.0.8",
"private": true,
"main": "dist-electron/index.js",
Expand All @@ -18,6 +17,7 @@
"electron-trpc": "0.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"superjson": "^1.12.2",
"zod": "^3.19.1"
},
"devDependencies": {
Expand Down
44 changes: 44 additions & 0 deletions examples/basic-react-superjson/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from 'react';
import ReactDom from 'react-dom';
import { ipcLink } from 'electron-trpc/renderer';
import superjson from 'superjson';
import { createTRPCReact } from '@trpc/react-query';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { AppRouter } from '../electron/api';

const trpcReact = createTRPCReact<AppRouter>();

function App() {
const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() =>
trpcReact.createClient({
links: [ipcLink()],
transformer: superjson,
})
);

return (
<trpcReact.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>
<HelloElectron />
</QueryClientProvider>
</trpcReact.Provider>
);
}

function HelloElectron() {
const { data } = trpcReact.greeting.useQuery({ name: 'Electron' });
trpcReact.subscription.useSubscription(undefined, {
onData: (data) => {
console.log(data);
},
});

if (!data) {
return null;
}

return <div>{data.text}</div>;
}

ReactDom.render(<App />, document.getElementById('react-root'));
78 changes: 78 additions & 0 deletions examples/basic-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# examples/basic

## 0.0.8

### Patch Changes

- Updated dependencies [[`cbae157`](https://github.com/jsonnull/electron-trpc/commit/cbae1570ddeab2405950806656c0d4fc19d72855)]:
- electron-trpc@0.4.2

## 0.0.7

### Patch Changes

- Updated dependencies [[`b73c1a8`](https://github.com/jsonnull/electron-trpc/commit/b73c1a89c77258bf4372991fda563d6fa0ba299f)]:
- electron-trpc@0.4.1

## 0.0.6

### Patch Changes

- Updated dependencies [[`70e8e5c`](https://github.com/jsonnull/electron-trpc/commit/70e8e5c5f3e2654d055663a286c4107a66f362e7)]:
- electron-trpc@0.4.0

## 0.0.5

### Patch Changes

- Updated dependencies [[`46d79ef`](https://github.com/jsonnull/electron-trpc/commit/46d79efde7ccc12cd1e99eb086413aa83bda29f8)]:
- electron-trpc@0.3.2

## 0.0.4

### Patch Changes

- Updated dependencies [[`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730), [`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730), [`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730)]:
- electron-trpc@0.3.1

## 0.0.3

### Patch Changes

- Updated dependencies [[`b67f2a7`](https://github.com/jsonnull/electron-trpc/commit/b67f2a7a87cd77b88d337e6996d78c6507a9c187)]:
- electron-trpc@0.3.0

## 0.0.2

### Patch Changes

- Updated dependencies [[`c9031f5`](https://github.com/jsonnull/electron-trpc/commit/c9031f5b521095d3c648fc905b642471e875d86f)]:
- electron-trpc@0.2.1

## 0.0.1

### Patch Changes

- Updated dependencies [[`231afea`](https://github.com/jsonnull/electron-trpc/commit/231afea9f21f0d4ba7f12c37fd781f22ca5d4141), [`960999f`](https://github.com/jsonnull/electron-trpc/commit/960999f5c2fec8b70152cfdf6cadc737c60edd48), [`3c76498`](https://github.com/jsonnull/electron-trpc/commit/3c76498c152e92fe1b084d3e7a5170d8f2c1dee3), [`7c7ee89`](https://github.com/jsonnull/electron-trpc/commit/7c7ee89b45c6c27527e26b0a6100fc0cb41d8ba6), [`ddc11cb`](https://github.com/jsonnull/electron-trpc/commit/ddc11cb1f1502568a028476acdefdb8d95d9562c), [`4615cf6`](https://github.com/jsonnull/electron-trpc/commit/4615cf63c382a0ea21781efb5093a531cc6378e6), [`006d01e`](https://github.com/jsonnull/electron-trpc/commit/006d01e73a995f756be622769192444bba3b4a87), [`c46f700`](https://github.com/jsonnull/electron-trpc/commit/c46f700b6171835a5b00d6d2c44061acdcd49874), [`42f2b09`](https://github.com/jsonnull/electron-trpc/commit/42f2b09efbaf322af42df176b74f72b972724f99), [`d2870a4`](https://github.com/jsonnull/electron-trpc/commit/d2870a4ef4429053c6a0d3e44bb204d0177adda9)]:
- electron-trpc@0.2.0

## 0.0.1-next.2

### Patch Changes

- Updated dependencies [[`169c47f`](https://github.com/jsonnull/electron-trpc/commit/169c47f325de8899784187af06140c29758b0c0a)]:
- electron-trpc@0.2.0-next.7

## 0.0.1-next.1

### Patch Changes

- Updated dependencies [[`a2103c4`](https://github.com/jsonnull/electron-trpc/commit/a2103c4e9789741aa98aa057fcebf78e4f339d9b)]:
- electron-trpc@0.2.0-next.6

## 0.0.1-next.0

### Patch Changes

- Updated dependencies [[`333197f`](https://github.com/jsonnull/electron-trpc/commit/333197fb3e567aa37f350af992d123f8f8ed6796)]:
- electron-trpc@0.2.0-next.5
File renamed without changes.
28 changes: 28 additions & 0 deletions examples/basic-react/electron/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from 'path';
import { app, BrowserWindow } from 'electron';
import { createIPCHandler } from 'electron-trpc/main';
import { router } from './api';

process.env.DIST = path.join(__dirname, '../dist');
process.env.PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public');

const preload = path.join(__dirname, './preload.js');
const url = process.env['VITE_DEV_SERVER_URL'];

app.on('ready', () => {
const win = new BrowserWindow({
webPreferences: {
preload,
},
});

createIPCHandler({ router, windows: [win] });

if (url) {
win.loadURL(url);
} else {
win.loadFile(path.join(process.env.DIST, 'index.html'));
}

win.show();
});
14 changes: 14 additions & 0 deletions examples/basic-react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
<title>Hello from Electron renderer!</title>
</head>
<body>
<div id="react-root"></div>
</body>
<script type="module" src="./src/index.tsx"></script>
</html>
30 changes: 30 additions & 0 deletions examples/basic-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "examples/basic-react",
"version": "0.0.8",
"private": true,
"main": "dist-electron/index.js",
"license": "MIT",
"scripts": {
"start": "vite",
"build": "vite build"
},
"dependencies": {
"@tanstack/react-query": "^4.8.0",
"@trpc/client": "10.4.3",
"@trpc/react-query": "10.4.3",
"@trpc/server": "10.4.3",
"electron": "^21.2.2",
"electron-trpc": "0.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zod": "^3.19.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^3.0.0",
"vite": "^3.0.3",
"vite-plugin-electron": "^0.11.0"
}
}
5 changes: 5 additions & 0 deletions examples/basic-react/preload/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { exposeElectronTRPC } from 'electron-trpc/main';

process.once('loaded', async () => {
exposeElectronTRPC();
});
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/basic-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "esnext"],
"module": "esnext",
"moduleResolution": "node16",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"useDefineForClassFields": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"include": ["./*.ts", "./*.tsx"],
"exclude": ["node_modules"]
}
21 changes: 21 additions & 0 deletions examples/basic-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import electron from 'vite-plugin-electron';

export default defineConfig({
mode: 'development',
plugins: [
react(),
electron([
{
entry: 'electron/index.ts',
},
{
entry: 'preload/preload.ts',
onstart(options) {
options.reload();
},
},
]),
],
});
Loading