@@ -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]
3232import { registerService } from ' @webext-core/proxy-service' ;
3333import { 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
3737const 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]
4444import { 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
5151await mathService .fibonacci (100 );
@@ -129,20 +129,20 @@ Now that you have a service implemented, we need to register it in the backgroun
129129import type { ProxyServiceKey } from ' @webext-core/proxy-service' ;
130130import 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]
136136import { registerService } from ' @webext-core/proxy-service' ;
137137import { openDB } from ' idb' ;
138138import { 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.
142142const idbPromise = openDB (" todos" , ... );
143143
144144const 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' ;
174174import { createProxyService } from ' @webext-core/proxy-service' ;
175175
176176// Inside content scripts
177- const todosRepo = createProxyService (TodosRepoKey );
177+ const todosRepo = createProxyService (TODOS_REPO_KEY );
178178const todos = await todosRepo .getAll ();
179179console .log (todos );
180180```
0 commit comments