Skip to content

Commit 2e0c74c

Browse files
committed
working on correcting helper functions that could contribute to memory leaks
1 parent 9118c20 commit 2e0c74c

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modular-openscriptjs",
3-
"version": "2.0.14",
3+
"version": "2.0.15",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const putContext = (referenceName, qualifiedName) =>
6464
contextProvider.load(referenceName, qualifiedName);
6565
const lazyFor = Utils.lazyFor;
6666
const each = Utils.each;
67+
const parsePayload = Utils.parsePayload;
6768
const component = (componentId) => app("repository").findComponent(componentId);
6869
const eData = (meta = {}, message = {}) => {
6970
return new EventData().meta(meta).message(message).encode();
@@ -189,6 +190,7 @@ export {
189190
component,
190191
eData,
191192
payload,
193+
parsePayload,
192194
ojsRouterEvents,
193195
removeNodeModifications,
194196
removeNode,
@@ -233,6 +235,7 @@ export default {
233235
component,
234236
eData,
235237
payload,
238+
parsePayload,
236239
ojsRouterEvents,
237240
removeNodeModifications,
238241
removeNode,

src/utils/Utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ export default class Utils {
77
/**
88
* Runs a foreach on an array
99
* @param {Iterable} array
10-
* @param {Function} callback
10+
* @param {(v: any, index: Number) => any} callback
1111
*/
12-
static each = (array, callback = (v, index) => v) => {
12+
static each = (array, callback = null) => {
13+
if (!callback) callback = (v) => v;
14+
1315
let output = [];
14-
if (Array.isArray(array)) {
15-
array.forEach((v, i) => output.push(callback(v, i)));
16-
} else {
17-
for (let k in array) output.push(callback(array[k], k));
18-
}
16+
17+
for (let k in array) output.push(callback(array[k], k));
18+
1919
return output;
2020
};
2121

2222
/**
2323
* Iterates over array elements using setTimeout
2424
* @param {Iterable} array
25-
* @param {Function} callback
25+
* @param {(v: any) => any} callback
2626
*/
27-
static lazyFor = (array, callback = (v) => v) => {
27+
static lazyFor = (array, callback = null) => {
28+
if (!callback) callback = (v) => v;
29+
2830
let index = 0;
2931

3032
if (array.length < 1) return;

0 commit comments

Comments
 (0)