Skip to content
Permalink
Browse files
feat: add configurable Root.prototype.fetch
  • Loading branch information
recih committed Jun 12, 2020
1 parent 1b8aa8f commit ad3cffdc5a54a7c94830674270d3386e1a2b58fc
Showing with 19 additions and 1 deletion.
  1. +8 −0 index.d.ts
  2. +11 −1 src/root.js
@@ -1243,6 +1243,14 @@ export class Root extends NamespaceBase {
*/
public resolvePath(origin: string, target: string): (string|null);

/**
* Fetch content from file path or url
* This method exists so you can override it with your own logic.
* @param path File path or url
* @param callback Callback function
*/
public fetch(path: string, callback: FetchCallback): void;

/**
* Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
* @param filename Names of one or multiple files to load
@@ -61,6 +61,16 @@ Root.fromJSON = function fromJSON(json, root) {
*/
Root.prototype.resolvePath = util.path.resolve;

/**
* Fetch content from file path or url
* This method exists so you can override it with your own logic.
* @function
* @param {string} path File path or url
* @param {FetchCallback} callback Callback function
* @returns {undefined}
*/
Root.prototype.fetch = util.fetch;

// A symbol-like function to safely signal synchronous loading
/* istanbul ignore next */
function SYNC() {} // eslint-disable-line no-empty-function
@@ -168,7 +178,7 @@ Root.prototype.load = function load(filename, options, callback) {
process(filename, source);
} else {
++queued;
util.fetch(filename, function(err, source) {
self.fetch(filename, function(err, source) {
--queued;
/* istanbul ignore if */
if (!callback)

0 comments on commit ad3cffd

Please sign in to comment.