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

Reduce luigi client and core bundle size #569

Merged
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
17 changes: 17 additions & 0 deletions .github/pull-request-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Thank you for your contribution. Before you submit the pull request:
1. Follow contributing guidelines, templates, the recommended Git workflow, and any related documentation.
2. Read and submit the required Contributor Licence Agreements (https://github.com/kyma-project/community/blob/master/CONTRIBUTING.md#agreements-and-licenses).
3. Test your changes and attach their results to the pull request.
4. Update the relevant documentation.
-->

**Description**

Changes proposed in this pull request:

- ...
- ...
- ...

**Related issue(s)**
<!-- If you refer to a particular issue, provide its number. For example, `Resolves #123`, `Fixes #43`, or `See also #33`. -->
7 changes: 6 additions & 1 deletion client/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Creates a random Id
* @private
*/
export const getRandomId = () => Math.floor(Math.random() * 1e9) + '';
export const getRandomId = () => {
// window.msCrypto for IE 11
return (window.crypto || window.msCrypto).getRandomValues(
new Uint32Array(1)
)[0];
};

/**
* Simple function check.
Expand Down
4 changes: 2 additions & 2 deletions client/src/uxManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LuigiClientBase } from './baseClass';
import { randomBytes } from 'crypto';
import { getRandomId } from './helpers';

/**
* Use the UX Manager to manage the appearance features in Luigi.
Expand Down Expand Up @@ -163,7 +163,7 @@ class UxManager extends LuigiClientBase {
*/
showAlert(settings) {
//generate random ID
settings.id = randomBytes(4).toString('hex');
settings.id = getRandomId();

if (settings.closeAfter && settings.closeAfter < 100) {
console.warn(
Expand Down
3 changes: 1 addition & 2 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@

if (!settings.id) {
//generate the ID in case it hasn't came from an old version of LuigiClient
const crypto = require('crypto');
settings.id = crypto.randomBytes(4).toString('hex');
settings.id = GenericHelpers.getRandomId();
}

if (
Expand Down
12 changes: 12 additions & 0 deletions core/src/utilities/helpers/generic-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Standalone or partly-standalone methods that are used widely through the whole app and are synchronous.

/**
* Creates a random Id
* @returns random numeric value {number}
* @private
*/
export const getRandomId = () => {
// window.msCrypto for IE 11
return (window.crypto || window.msCrypto).getRandomValues(
new Uint32Array(1)
)[0];
};

export const isFunction = anyParam =>
anyParam && {}.toString.call(anyParam) === '[object Function]';

Expand Down