Skip to content

Commit

Permalink
Merge pull request #112 from opencomponents/add-externals
Browse files Browse the repository at this point in the history
Add externals
  • Loading branch information
ricardo-devis-agullo committed Mar 30, 2024
2 parents 947d863 + 94f0b5b commit b46ed4b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
23 changes: 12 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
type Callback<T> = (err: NodeJS.ErrnoException | null, data: T) => void;

interface External {
global: string | string[];
url: string;
}
interface ExtendedExternal extends External {
name: string;
devUrl?: string;
}

interface TemplateRenderer {
getInfo: () => {
externals: Array<{
name: string;
global: string | string[];
url: string;
devUrl?: string;
}>;
externals: ExtendedExternal[];
type: string;
version: string;
};
}

type Template = {
externals: Array<{ global: string | string[]; url: string }>;
externals: External[];
};
interface CompileOptions {
templates?: Record<string, Template> | TemplateRenderer[];
retryInterval?: number;
retryLimit?: number;
/**
* JavaScript as a string code to be executed before rendering the templates
*/
beforeRender?: string;
externals?: External[];
}
type Compiled = { code: string; map: string; dev: string };

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oc-client-browser",
"version": "1.7.9",
"version": "1.7.10",
"description": "OC browser client",
"main": "index.js",
"types": "index.d.ts",
Expand Down
14 changes: 8 additions & 6 deletions src/oc-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals define, exports, require, globalThis, __REGISTERED_TEMPLATES_PLACEHOLDER__, __DEFAULT_RETRY_INTERVAL__, __DEFAULT_RETRY_LIMIT__, __BEFORE_RENDER__ */
/* globals define, exports, require, globalThis, __REGISTERED_TEMPLATES_PLACEHOLDER__, __DEFAULT_RETRY_INTERVAL__, __DEFAULT_RETRY_LIMIT__, __EXTERNALS__ */
/* eslint no-var: 'off' */
/* eslint prefer-arrow-callback: 'off' */

Expand Down Expand Up @@ -100,7 +100,8 @@ var oc = oc || {};
}
};

var registeredTemplates = __REGISTERED_TEMPLATES_PLACEHOLDER__;
var registeredTemplates = __REGISTERED_TEMPLATES_PLACEHOLDER__,
externals = __EXTERNALS__;

function registerTemplates(templates, overwrite) {
templates = Array.isArray(templates) ? templates : [templates];
Expand Down Expand Up @@ -690,11 +691,12 @@ var oc = oc || {};
}
});
};

__BEFORE_RENDER__;

// render the components
oc.ready(oc.renderUnloadedComponents);
oc.ready(function () {
oc.requireSeries(externals, function () {
oc.renderUnloadedComponents();
});
});

// expose public variables and methods
exports = oc;
Expand Down
2 changes: 1 addition & 1 deletion tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getFiles({ sync = false, conf = {} }) {
'__REGISTERED_TEMPLATES_PLACEHOLDER__',
JSON.stringify(registeredTemplates)
)
.replaceAll('__BEFORE_RENDER__', conf.beforeRender || '')
.replaceAll('__EXTERNALS__', conf.externals || '[]')
.replaceAll('__DEFAULT_RETRY_LIMIT__', conf.retryLimit || 30)
.replaceAll('__DEFAULT_RETRY_INTERVAL__', conf.retryInterval || 5000);

Expand Down

0 comments on commit b46ed4b

Please sign in to comment.