How does web worker call methods defined in Typescript class?Evaluate Typescript from string?How to change an element's class with JavaScript?How to manage a redirect request after a jQuery Ajax callHow do I add a class to a given element?How does JavaScript .prototype work?How to check a not-defined variable in JavaScriptHow can I select an element with multiple classes in jQuery?How does the “this” keyword work?How does data binding work in AngularJS?How do I return the response from an asynchronous call?How does Facebook disable the browser's integrated Developer Tools?

If a non-friend comes across my Steam Wishlist, how easily can he gift me one of the games?

How can a dictatorship government be beneficial to a dictator in a post-scarcity society?

How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?

How can I get a player to accept that they should stop trying to pull stunts without thinking them through first?

Why does this quadratic expression have three zeroes?

Is the genetic term "polycistronic" still used in modern biology?

Can a Beast Master ranger have its beast chase down and attack enemies?

C program to parse source code of another language

What is a solution?

Modulus Operandi

How would my creatures handle groups without a strong concept of numbers?

Are there any sports for which the world's best player is female?

As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?

Print the last, middle and first character of your code

Graduate student with abysmal English writing skills, how to help

Why were Er and Onan punished if they were under 20?

Is anyone advocating the promotion of homosexuality in UK schools?

Why didn't Thanos kill all the Dwarves on Nidavellir?

Cops: The Hidden OEIS Substring

Confirming the Identity of a (Friendly) Reviewer After the Reviews

Does throwing a penny at a train stop the train?

Why is a Gelman-Rubin diagnostic of < 1.1 considered acceptable?

When casting Eldritch Blast with the Agonizing Blast eldritch invocation, what do I add to my damage roll?

Changing trains in the Netherlands



How does web worker call methods defined in Typescript class?


Evaluate Typescript from string?How to change an element's class with JavaScript?How to manage a redirect request after a jQuery Ajax callHow do I add a class to a given element?How does JavaScript .prototype work?How to check a not-defined variable in JavaScriptHow can I select an element with multiple classes in jQuery?How does the “this” keyword work?How does data binding work in AngularJS?How do I return the response from an asynchronous call?How does Facebook disable the browser's integrated Developer Tools?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to move heavy calculation task or method-calls to separate web workers. I am using URL.createObjectURL(blob) to inject worker code. But from the code, it has to call some other functions which are defined in Typescript (it is hard to put all complex logic in the worker's blob).



let workers = ;

export function mapWorker<T, R>(cb: (value: T) => R, input: any): Observable<R>

const subject = new Subject<R>();
let workerString = cb.toString();
let worker: Worker;

if (workers[workerString])

worker = workers[workerString];
else
worker = createStaticWorker(cb);
workers[workerString] = worker;


worker.onmessage = e => subject.next(e.data);
worker.onerror = err => subject.error(err);
worker.postMessage(input);
return subject;


export function createStaticWorker(fn: Function): Worker

const blob = new Blob(
[ 'self.cb = ', fn.toString(), ';',
'self.onmessage = function (e) self.postMessage(self.cb(e.data)) '
],
type: 'text/javascript'

);
const url = URL.createObjectURL(blob);
return new Worker(url);



When using it, I did this.



 mapWorker(x =>

return Helper.AsyncCalc(x as Array<any>);
, inputs).subscribe(value => this.areas = value);


Then 'Helper.AsyncCalc' was the method defined in Helper.ts which contains majority of the logic. I noted that in run time the 'helper' name has been
compiled to different name in JS which led to an error saying that was undefined. Could someone help on this? Is there any way to call Typescript method from that js inline method?



Thanks so much in advance.










share|improve this question






















  • I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

    – Kaiido
    Mar 26 at 3:11

















0















I am trying to move heavy calculation task or method-calls to separate web workers. I am using URL.createObjectURL(blob) to inject worker code. But from the code, it has to call some other functions which are defined in Typescript (it is hard to put all complex logic in the worker's blob).



let workers = ;

export function mapWorker<T, R>(cb: (value: T) => R, input: any): Observable<R>

const subject = new Subject<R>();
let workerString = cb.toString();
let worker: Worker;

if (workers[workerString])

worker = workers[workerString];
else
worker = createStaticWorker(cb);
workers[workerString] = worker;


worker.onmessage = e => subject.next(e.data);
worker.onerror = err => subject.error(err);
worker.postMessage(input);
return subject;


export function createStaticWorker(fn: Function): Worker

const blob = new Blob(
[ 'self.cb = ', fn.toString(), ';',
'self.onmessage = function (e) self.postMessage(self.cb(e.data)) '
],
type: 'text/javascript'

);
const url = URL.createObjectURL(blob);
return new Worker(url);



When using it, I did this.



 mapWorker(x =>

return Helper.AsyncCalc(x as Array<any>);
, inputs).subscribe(value => this.areas = value);


Then 'Helper.AsyncCalc' was the method defined in Helper.ts which contains majority of the logic. I noted that in run time the 'helper' name has been
compiled to different name in JS which led to an error saying that was undefined. Could someone help on this? Is there any way to call Typescript method from that js inline method?



Thanks so much in advance.










share|improve this question






















  • I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

    – Kaiido
    Mar 26 at 3:11













0












0








0








I am trying to move heavy calculation task or method-calls to separate web workers. I am using URL.createObjectURL(blob) to inject worker code. But from the code, it has to call some other functions which are defined in Typescript (it is hard to put all complex logic in the worker's blob).



let workers = ;

export function mapWorker<T, R>(cb: (value: T) => R, input: any): Observable<R>

const subject = new Subject<R>();
let workerString = cb.toString();
let worker: Worker;

if (workers[workerString])

worker = workers[workerString];
else
worker = createStaticWorker(cb);
workers[workerString] = worker;


worker.onmessage = e => subject.next(e.data);
worker.onerror = err => subject.error(err);
worker.postMessage(input);
return subject;


export function createStaticWorker(fn: Function): Worker

const blob = new Blob(
[ 'self.cb = ', fn.toString(), ';',
'self.onmessage = function (e) self.postMessage(self.cb(e.data)) '
],
type: 'text/javascript'

);
const url = URL.createObjectURL(blob);
return new Worker(url);



When using it, I did this.



 mapWorker(x =>

return Helper.AsyncCalc(x as Array<any>);
, inputs).subscribe(value => this.areas = value);


Then 'Helper.AsyncCalc' was the method defined in Helper.ts which contains majority of the logic. I noted that in run time the 'helper' name has been
compiled to different name in JS which led to an error saying that was undefined. Could someone help on this? Is there any way to call Typescript method from that js inline method?



Thanks so much in advance.










share|improve this question














I am trying to move heavy calculation task or method-calls to separate web workers. I am using URL.createObjectURL(blob) to inject worker code. But from the code, it has to call some other functions which are defined in Typescript (it is hard to put all complex logic in the worker's blob).



let workers = ;

export function mapWorker<T, R>(cb: (value: T) => R, input: any): Observable<R>

const subject = new Subject<R>();
let workerString = cb.toString();
let worker: Worker;

if (workers[workerString])

worker = workers[workerString];
else
worker = createStaticWorker(cb);
workers[workerString] = worker;


worker.onmessage = e => subject.next(e.data);
worker.onerror = err => subject.error(err);
worker.postMessage(input);
return subject;


export function createStaticWorker(fn: Function): Worker

const blob = new Blob(
[ 'self.cb = ', fn.toString(), ';',
'self.onmessage = function (e) self.postMessage(self.cb(e.data)) '
],
type: 'text/javascript'

);
const url = URL.createObjectURL(blob);
return new Worker(url);



When using it, I did this.



 mapWorker(x =>

return Helper.AsyncCalc(x as Array<any>);
, inputs).subscribe(value => this.areas = value);


Then 'Helper.AsyncCalc' was the method defined in Helper.ts which contains majority of the logic. I noted that in run time the 'helper' name has been
compiled to different name in JS which led to an error saying that was undefined. Could someone help on this? Is there any way to call Typescript method from that js inline method?



Thanks so much in advance.







javascript angular typescript web






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 2:26









RichRich

429 bronze badges




429 bronze badges












  • I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

    – Kaiido
    Mar 26 at 3:11

















  • I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

    – Kaiido
    Mar 26 at 3:11
















I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

– Kaiido
Mar 26 at 3:11





I am really not into TypeScript nor Angular, but your question basically asks how to eval TypeScript source at run time, just like this question did before. So I won't use mjolnir here, but if you think your question indeed is the same as this one, let me know, so I can link them together.

– Kaiido
Mar 26 at 3:11












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348991%2fhow-does-web-worker-call-methods-defined-in-typescript-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348991%2fhow-does-web-worker-call-methods-defined-in-typescript-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript