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

Error in web worker using importScripts(defiant.min.js) #83

Closed
kskoeldMW opened this issue Apr 24, 2017 · 6 comments
Closed

Error in web worker using importScripts(defiant.min.js) #83

kskoeldMW opened this issue Apr 24, 2017 · 6 comments

Comments

@kskoeldMW
Copy link

I'm trying to use defiant.js in a web worker, since I'm doing heavy computation in addition to the JSON.search.
However I keep getting a

Uncaught Error: Uncaught ReferenceError: Defiant is not defined

I created a simple example using part of the demo code.
Archive.zip

@hbi99
Copy link
Owner

hbi99 commented Apr 26, 2017

Hi @kskoeldMW,
There is already support for web workers in Defiant.js
Look at the code below...also, you should yse the latest version - which 1.4.2.

Kind regards

<script src="defiant.min.js"></script>
<script>

var obj = {
	"car": [
		{"id": 10, "color": "silver", "name": "Volvo"},
		{"id": 11, "color": "red",    "name": "Saab"},
		{"id": 12, "color": "red",    "name": "Peugeot"},
		{"id": 13, "color": "yellow", "name": "Porsche"}
	],
	"bike": [
		{"id": 20, "color": "black", "name": "Cannondale"},
		{"id": 21, "color": "red",   "name": "Shimano"}
	]
};

Defiant.getSnapshot(obj, function(snapshot) {
    var found = JSON.search(snapshot, '//car');
    console.log(found);
});
	
</script>

@hbi99 hbi99 closed this as completed Apr 26, 2017
@kskoeldMW
Copy link
Author

Hi @hbi99
I know of the getSnapshot option, but unless I have misunderstood some fundamental things about it it doesn't give me access to defiant from within my own web-worker.
I can execute the Snapshot in the main thread and then post the result to my web-worker, however the large JSON (5-15mb) is handled only in the web-worker. I would have to pass it over to the main thread, run the Snapshot (which is executed in another web-worker) and then pass the result back to my WW.
Since I'm using the JSON.search quite often that would induce a lot of unnecessary overhead on the main thread.
So is there a way to access the defiant functionality directly within a web-worker?

@hbi99
Copy link
Owner

hbi99 commented Apr 26, 2017

No...you can not access Defiant from within a web worker. I'd recommend that you look into the types of objects / scripts you can access into a web worker...defiant is not on of them.

@kskoeldMW
Copy link
Author

Ok thanks - too bad, since I really like the ease-of-use and speed of defiant.
Oh well, than I have to look for another solution.

@hbi99
Copy link
Owner

hbi99 commented Apr 26, 2017

I wonder if you should familiarise more with web workers...messaging to and from a ww-thread is limited.

Anywho...good luck

@kskoeldMW
Copy link
Author

Yes, thats exactly why doing that would not be a wise decision :)
Thanks for your precious time though ;)

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