diff --git a/extensions/markdown/package.json b/extensions/markdown/package.json index b13f665dd21..4d66b03ef5e 100644 --- a/extensions/markdown/package.json +++ b/extensions/markdown/package.json @@ -283,12 +283,14 @@ }, "devDependencies": { "@types/highlight.js": "9.1.10", + "@types/lodash.throttle": "^4.1.3", "@types/markdown-it": "0.0.2", "@types/node": "7.0.43", + "lodash.throttle": "^4.1.1", "ts-loader": "^4.0.1", "typescript": "^2.7.2", "vscode": "^1.1.10", "webpack": "^4.1.0", "webpack-cli": "^2.0.10" } -} +} \ No newline at end of file diff --git a/extensions/markdown/preview-src/index.ts b/extensions/markdown/preview-src/index.ts index 0ca9d1a1b08..0d103c5b4a2 100644 --- a/extensions/markdown/preview-src/index.ts +++ b/extensions/markdown/preview-src/index.ts @@ -8,30 +8,7 @@ import { postCommand, postMessage } from './messaging'; import { onceDocumentLoaded } from './events'; import { getEditorLineNumberForPageOffset, scrollToRevealSourceLine } from './scroll-sync'; import { ActiveLineMarker } from './activeLineMarker'; - -// From https://remysharp.com/2010/07/21/throttling-function-calls -function throttle(fn: (x: any) => any, threshhold: any, scope?: any) { - threshhold = threshhold || (threshhold = 250); - var last: any, deferTimer: any; - return function (this: any, ...x: any[]) { - var context = scope || this; - - var now = +new Date, - args = arguments; - if (last && now < last + threshhold) { - // hold on to it - clearTimeout(deferTimer); - deferTimer = setTimeout(function () { - last = now; - fn.apply(context, args); - }, threshhold + last - now); - } else { - last = now; - fn.apply(context, args); - } - }; -} - +import throttle = require('lodash.throttle'); var scrollDisabled = true; const marker = new ActiveLineMarker(); diff --git a/extensions/markdown/preview-src/tsconfig.json b/extensions/markdown/preview-src/tsconfig.json index cf586892b7c..9684d1ec2d9 100644 --- a/extensions/markdown/preview-src/tsconfig.json +++ b/extensions/markdown/preview-src/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "outDir": "./dist/", - "module": "es6", + "module": "commonjs", "target": "es6", "jsx": "react", "sourceMap": true, diff --git a/extensions/markdown/yarn.lock b/extensions/markdown/yarn.lock index f8a993b2347..f38d9ea33aa 100644 --- a/extensions/markdown/yarn.lock +++ b/extensions/markdown/yarn.lock @@ -10,6 +10,16 @@ version "9.1.10" resolved "https://registry.yarnpkg.com/@types/highlight.js/-/highlight.js-9.1.10.tgz#b621f809cd9573b80992b90cffc5788208e3069c" +"@types/lodash.throttle@^4.1.3": + version "4.1.3" + resolved "https://registry.yarnpkg.com/@types/lodash.throttle/-/lodash.throttle-4.1.3.tgz#8bfa4fec519d09ebce56c815bcbff3e55c604db9" + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.104" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.104.tgz#53ee2357fa2e6e68379341d92eb2ecea4b11bb80" + "@types/markdown-it@0.0.2": version "0.0.2" resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-0.0.2.tgz#5d9ad19e6e6508cdd2f2596df86fd0aade598660" @@ -3277,6 +3287,10 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" +lodash.throttle@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4" + lodash@^4.11.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0: version "4.17.5" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"