Skip to content

Commit

Permalink
feat: Gun in a worker - OK, SEA - NOT YET
Browse files Browse the repository at this point in the history
  • Loading branch information
davay42 committed Apr 26, 2023
1 parent 6827fa6 commit 2555428
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineConfig({
clearScreen: false,
server: {
port: 3142,
strictPort: true,
strictPort: false,
fs: {
allow: ['../']
}
Expand Down
5 changes: 4 additions & 1 deletion composables/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const dirname = path.dirname(filename);

export default defineConfig({
plugins: [
moduleExclude("text-encoding"),
// moduleExclude("text-encoding"),
checker({
typescript: {
buildMode: true
Expand All @@ -26,6 +26,9 @@ export default defineConfig({
minifyInternalExports: false,
},
},
commonjsOptions: {
ignoreDynamicRequires: true
}
},
optimizeDeps: {
include: [
Expand Down
5 changes: 5 additions & 0 deletions src/gun/useGun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import "gun/lib/store";
import "gun/lib/rindexed";
import "gun/lib/webrtc";

import GunWorker from './useGunWorker'

GunWorker.post('Welcome to Gun-Vue')


import { relay } from './useRelay'

Expand All @@ -33,6 +37,7 @@ export let gun: IGunInstance;
*/

export function useGun(options: GunOptions = { localStorage: false }): IGunInstance {

if (!gun) {
const opts = { peers: [relay.peer] }
if (typeof options === 'object') {
Expand Down
12 changes: 12 additions & 0 deletions src/gun/useGunWorker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ts-ignore
import worker from './worker.js?worker&inline'
import { useWebWorker } from '@vueuse/core'
import { watch } from 'vue'

const GunWorker = useWebWorker(worker)

GunWorker.post('Worker check up')

watch(GunWorker.data, d => console.log('Recieved:', d), { immediate: true })

export default GunWorker
13 changes: 13 additions & 0 deletions src/gun/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
console.log('Worker initiated')

import Gun from "gun/gun";
// import { default as SEA } from "gun/sea.js";

onmessage = m => {
console.log('In worker:', m.data)
const gun = Gun()
gun.get('check').get('time').once(d => console.log(d))
gun.get('check').get('time').put(Date.now())
postMessage(`Answer: ${m.data}`)
}

0 comments on commit 2555428

Please sign in to comment.