From e1e22e7bcf899dc5bbdcc429f793bd1d0e6378f5 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Fri, 16 Nov 2018 09:38:53 +0700 Subject: [PATCH] Node + browser-friendly index.ts. --- common/predictive-text/worker/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/predictive-text/worker/index.ts b/common/predictive-text/worker/index.ts index 7c14f86c20..cab8577f0e 100644 --- a/common/predictive-text/worker/index.ts +++ b/common/predictive-text/worker/index.ts @@ -1,4 +1,14 @@ // Dummy module for getting environment setup. -module.exports ={ - hello: () => 'hello' +class MyWorker { + public hello() { + return 'hello'; + } +} + +// The technique below allows code to work both in-browser and in Node. +if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { + module.exports = new MyWorker(); +} else { + //@ts-ignore + window.worker = new MyWorker(); } \ No newline at end of file