-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
213 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
components/crystallize-import/src/core.server/services.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EventEmitter } from 'events'; | ||
|
||
declare global { | ||
// eslint-disable-next-line no-var | ||
var __services: Awaited<ReturnType<typeof build>>; | ||
} | ||
|
||
export const buildServices = async () => { | ||
if (!global.__services) { | ||
global.__services = await build(); | ||
} | ||
return global.__services; | ||
}; | ||
|
||
const build = async () => { | ||
const emitter = new EventEmitter(); | ||
return { | ||
emitter, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
components/crystallize-import/src/routes/api.import.stream.$id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { LoaderFunctionArgs } from '@remix-run/node'; | ||
import { eventStream } from 'remix-utils/sse/server'; | ||
import { buildServices } from '~/core.server/services.server'; | ||
|
||
export async function loader({ request, params }: LoaderFunctionArgs) { | ||
const { emitter } = await buildServices(); | ||
|
||
return eventStream(request.signal, (send) => { | ||
const handler = (data: any) => { | ||
send({ event: 'log', data: JSON.stringify(data) }); | ||
}; | ||
emitter.addListener(params.id!, handler); | ||
send({ event: 'init', data: 'Started' }); | ||
const interval = setInterval(() => { | ||
send({ event: 'ping', data: 'pong' }); | ||
}, 10000); | ||
return function clear() { | ||
emitter.removeListener(params.id!, handler); | ||
clearInterval(interval); | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.