Skip to content
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

Allow it to live in a worker (maybe?) #492

Closed
jakearchibald opened this issue Feb 9, 2015 · 2 comments
Closed

Allow it to live in a worker (maybe?) #492

jakearchibald opened this issue Feb 9, 2015 · 2 comments

Comments

@jakearchibald
Copy link
Contributor

I'm using (or about to use) prismjs on https://jakearchibald.github.io/svgomg/. I want it to live in a worker because I'm (potentially) dealing with large bits of markup, but also the worker is a convenient script loader.

Anyway, I didn't want to spin up a new worker for each usage, but prism wants to terminate after handling a message event. I hacked around it by removing addEventListener while it initialises, making it think it's in a node environment https://github.com/jakearchibald/svgomg/blob/feature/code-view/src/js/prism-worker/index.js

Dunno if this is something you're interested in making less hacky, but thought I'd bring it up anyway.

@Golmote Golmote closed this as completed in e42a228 Sep 3, 2015
@Golmote
Copy link
Contributor

Golmote commented Sep 3, 2015

Hi, sorry for the delay.
I just added a parameter in the worker message that forces it to close after highlighting. So when you use it directly from the outside, it should not close itself unless you pass the parameter.

var worker = new Worker('prism.js');
worker.onmessage = function(evt) {
    console.log(JSON.parse(evt.data));
};
worker.postMessage(JSON.stringify({
    language: 'markup',
    code: '<span>'
}));
// Here, the worker is still open!
worker.postMessage(JSON.stringify({
    language: 'markup',
    code: '<div>',
    immediateClose: true
}));
// Now the worker is closed.

@jakearchibald
Copy link
Contributor Author

Ohh thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants