Skip to content

Commit 7d2c74d

Browse files
committed
update docs to follow standards and be consistent
1 parent d9a5e5e commit 7d2c74d

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

docs/content/proxy-service/0.installation.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ import type { MathService } from './MathService';
2525
// ^^^^ IMPORTANT: do not import the math service's value, just it's type.
2626

2727
// 2. [Optional] Define a key with a branded type to ensure type-safety
28-
export const MathServiceKey = 'math-service' as ProxyServiceKey<MathService>;
28+
export const MATH_SERVICE_KEY = 'math-service' as ProxyServiceKey<MathService>;
2929
```
3030

3131
```ts [background.ts]
3232
import { registerService } from '@webext-core/proxy-service';
3333
import { MathService } from './MathService';
34-
import { MathServiceKey } from './proxy-service-keys';
34+
import { MATH_SERVICE_KEY } from './proxy-service-keys';
3535

3636
// 3. Instantiate your service
3737
const mathService = new MathService();
3838

3939
// 4. Register the service BEFORE awaiting anything
40-
registerService(MathServiceKey, mathService);
40+
registerService(MATH_SERVICE_KEY, mathService);
4141
```
4242

4343
```ts [anywhere-else.ts]
4444
import { createProxyService } from './MathService';
45-
import { MathServiceKey } from './proxy-service-keys';
45+
import { MATH_SERVICE_KEY } from './proxy-service-keys';
4646

4747
// 5. Get a proxy of your service
48-
const mathService = createProxyService(MathServiceKey);
48+
const mathService = createProxyService(MATH_SERVICE_KEY);
4949

5050
// 6. Call methods like normal, they will execute in the background
5151
await mathService.fibonacci(100);
@@ -129,20 +129,20 @@ Now that you have a service implemented, we need to register it in the backgroun
129129
import type { ProxyServiceKey } from '@webext-core/proxy-service';
130130
import type { TodosRepo } from './todos-repo';
131131

132-
export const TodosRepoKey = 'todos-repo' as ProxyServiceKey<TodosRepo>;
132+
export const TODOS_REPO_KEY = 'todos-repo' as ProxyServiceKey<TodosRepo>;
133133
```
134134

135135
```ts [background.ts]
136136
import { registerService } from '@webext-core/proxy-service';
137137
import { openDB } from 'idb';
138138
import { createTodosRepo } from './todos-repo';
139-
import { TodosRepoKey } from './proxy-service-keys';
139+
import { TODOS_REPO_KEY } from './proxy-service-keys';
140140

141141
// DO NOT await the promise here. registerService must be called synchronously.
142142
const idbPromise = openDB("todos", ...);
143143

144144
const todosRepo = createTodosRepo(idbPromise);
145-
registerService(TodosRepoKey, todosRepo);
145+
registerService(TODOS_REPO_KEY, todosRepo);
146146
```
147147

148148
::
@@ -159,22 +159,22 @@ And that's it. You can now access your IndexedDB database from any JS context in
159159

160160
```html [extension-page.html]
161161
<script type="module">
162-
import { TodosRepoKey } from './proxy-service-keys';
162+
import { TODOS_REPO_KEY } from './proxy-service-keys';
163163
import { createProxyService } from '@webext-core/proxy-service';
164164
165165
// On your UIs
166-
const todosRepo = createProxyService(TodosRepoKey);
166+
const todosRepo = createProxyService(TODOS_REPO_KEY);
167167
const todos = await todosRepo.getAll();
168168
console.log(todos);
169169
</script>
170170
```
171171

172172
```ts [content-script.ts]
173-
import { TodosRepoKey } from './proxy-service-keys';
173+
import { TODOS_REPO_KEY } from './proxy-service-keys';
174174
import { createProxyService } from '@webext-core/proxy-service';
175175

176176
// Inside content scripts
177-
const todosRepo = createProxyService(TodosRepoKey);
177+
const todosRepo = createProxyService(TODOS_REPO_KEY);
178178
const todos = await todosRepo.getAll();
179179
console.log(todos);
180180
```

docs/content/proxy-service/2.service-keys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ import type { ProxyServiceKey } from '@webext-core/proxy-service';
2929
import type { MathService } from './math-service';
3030
// ^^^^ DO NOT FORGET THE type KEYWORD
3131

32-
export const MathServiceKey = 'math-service' as ProxyServiceKey<MathService>;
32+
export const MATH_SERVICE_KEY = 'math-service' as ProxyServiceKey<MathService>;
3333
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { registerService } from '@webext-core/proxy-service';
22

33
export default defineBackground(() => {
4-
registerService(MathServiceKey, new MathService());
4+
registerService(MATH_SERVICE_KEY, new MathService());
55
});

packages/proxy-service-demo/src/entrypoints/popup/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const [multiplyButton, multiplyPre] = getMathServiceElements('multiply');
1414
const [divideButton, dividePre] = getMathServiceElements('divide');
1515
const [factorialButton, factorialPre] = getMathServiceElements('factorial');
1616

17-
const mathService = createProxyService(MathServiceKey);
17+
const mathService = createProxyService(MATH_SERVICE_KEY);
1818

1919
addButton.addEventListener('click', async () => {
2020
addPre.innerText = 'Loading...';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { ProxyServiceKey } from '@webext-core/proxy-service';
22
import type { MathService } from './math-service';
33

4-
export const MathServiceKey = 'math-service' as ProxyServiceKey<MathService>;
4+
export const MATH_SERVICE_KEY = 'math-service' as ProxyServiceKey<MathService>;

packages/proxy-service/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { DeepAsync, Service } from './types';
21
import {
32
defineExtensionMessaging,
43
ExtensionMessagingConfig,
54
ExtensionMessenger,
65
RemoveListenerCallback,
76
} from '@webext-core/messaging';
7+
import { DeepAsync, Service } from './types';
88

99
/**
1010
* A type that ensures a service has only async methods.
@@ -66,19 +66,17 @@ interface ProxyServiceConstraint<_> {}
6666
* import type { ProxyServiceKey } from '@webext-core/proxy-service';
6767
* import type { MathService } from './math-service';
6868
*
69-
* export const ProxyServiceKey = {
70-
* MathService: 'MathService' as ProxyServiceKey<MathService>,
71-
* }
69+
* export const PROXY_SERVICE_KEY = 'math-service' as ProxyServiceKey<MathService>;
7270
*
7371
* // background.ts
74-
* import { ProxyServiceKey } from './utils/proxy-service-keys';
72+
* import { PROXY_SERVICE_KEY } from './utils/proxy-service-keys';
7573
*
76-
* registerService(ProxyServiceKey.MathService, new MathService())
74+
* registerService(PROXY_SERVICE_KEY, new MathService())
7775
*
7876
* // content-script.ts
79-
* import { ProxyServiceKey } from './utils/proxy-service-keys';
77+
* import { PROXY_SERVICE_KEY } from './utils/proxy-service-keys';
8078
*
81-
* const mathService = await createProxyService(ProxyServiceKey.MathService);
79+
* const mathService = await createProxyService(PROXY_SERVICE_KEY);
8280
* ```
8381
*/
8482
export type ProxyServiceKey<T> = string & ProxyServiceConstraint<T>;

0 commit comments

Comments
 (0)