Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

sourceMapProvider called multiple times #5

Open
moshest opened this issue Jun 29, 2019 · 2 comments
Open

sourceMapProvider called multiple times #5

moshest opened this issue Jun 29, 2019 · 2 comments

Comments

@moshest
Copy link

moshest commented Jun 29, 2019

It should use a caching mechanism like this:

const cache: { [fileUrl: string]: Promise<SourceMap> } = {};

// fetch file every request
function fetchFile(fileUrl: string): Promise<SourceMap>;

// fetch file only once
function sourceMapProvider(fileUrl: string): Promise<SourceMap> {
  if (!(fileUrl in cache)) {
    // this will return promise that will fetched only once
    cache[fileUrl] = fetchFile(fileUrl); 
  }
  
  return cache[fileUrl];
}
@kobiburnley
Copy link
Contributor

@moshest thanks for submitting the issue. We will take a close look at this.

@mckomo
Copy link
Contributor

mckomo commented Jul 1, 2019

@moshest This project is really in a early stage and I still don't have a complete vision regarding production usage of it. This is why I left a convenient way to provide your own sourceMapProvider. If your only need so far is a caching mechanism you can easily achieve that by memorizing one of the built-in source map providers. Take a look at the example below:

import memoize from "lodash/memoize" // although you can use any memoize function you like
import {StackRetracer, httpProvider} from "stack-retrace"

const sourceMapProvider = memoize(httpProvider)

const stackRetracer = new StackRetracer({ sourceMapProvider })

In the next version, I will definitely export types like RawSourceMaps so integrating your custom code will be easier and will not require any hacks as you presented here #4 (comment).

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

No branches or pull requests

3 participants