Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add externals #112

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading