-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Provide a way to load Prism from inside a Worker without listen… #1188
Conversation
7b50d60
to
7e767f8
Compare
LGTM. How about replacing |
Other alternatives that I can come up with are: |
@LeaVerou @zeitgeist87 Any advice on the naming? I'm receiving mixed signals there. :') |
Can't we autodetect this instead of requiring some special parameter? I believe worker environments can be detected, so why do we need this? |
@LeaVerou We must differentiate two cases where Prism might find itself inside a worker.
The core autodetects when it's in a Worker, but it only handles case 1. We need a param to handle explicitely case 2, so that we can skip attaching the listener for messages. |
I see. Can we instead explicitly handle case 1 somehow? That way including Prism from a worker would just work without any special syntax, and we can use whatever special syntax we want inside Prism when we create the worker for async highlighting. |
You could use `location.pathname` to test whether the worker script is
loaded via importScripts.
This "location" object is a WorkerLocation instance and only supported by
recent browser versions. Perhaps you can use this to select a reasonable
environment-dependent default, and allow users to override the default
(e.g. if the option is not supported).
Alternatively/additionally, detect the presence of the Prism global before
the script has loaded. If it was set, then a script has run before the
library was loaded, so you can then infer that `importScripts` had been
used.
|
@Rob--W Unless I missed something in your explanation, I can't see how this will help us differentiate when Prism is loaded as a worker and when it's loaded with @LeaVerou No, I can't think of any way to differentiate the two automatically. |
In both cases That having said, when loaded as a worker by Prism, |
Ok, I trust your judgement @Golmote :) |
7e767f8
to
e68fc1c
Compare
Ok, I went for the long explicit one: |
…ing to messages.
This should fix #1059 and #1172.
Usage from inside a worker:
Does that look good to you @ligaz @Rob--W @falsandtru?
I feel the naming is quite poor, but I couldn't come with any better name for this param.