@aemforms/af-core 0.22.56 → 0.22.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,10 @@ export declare type FunctionDefinition = {
7
7
  _signature: Array<any>;
8
8
  };
9
9
  declare class FunctionRuntimeImpl {
10
- private customFunctions;
10
+ private static instance;
11
+ private static customFunctions;
12
+ private constructor();
13
+ static getInstance(): FunctionRuntimeImpl;
11
14
  registerFunctions(functions: {
12
15
  [key: string]: FunctionDefinition | CustomFunction;
13
16
  }): void;
@@ -165,7 +165,12 @@ const createAction = (name, payload = {}) => {
165
165
  };
166
166
  class FunctionRuntimeImpl {
167
167
  constructor() {
168
- this.customFunctions = {};
168
+ }
169
+ static getInstance() {
170
+ if (!FunctionRuntimeImpl.instance) {
171
+ FunctionRuntimeImpl.instance = new FunctionRuntimeImpl();
172
+ }
173
+ return FunctionRuntimeImpl.instance;
169
174
  }
170
175
  registerFunctions(functions) {
171
176
  Object.entries(functions).forEach(([name, funcDef]) => {
@@ -176,7 +181,7 @@ class FunctionRuntimeImpl {
176
181
  const globals = {
177
182
  form: interpreter.globals.form,
178
183
  invoke: (funcName, ...args) => {
179
- return this.customFunctions[funcName]._func.call(undefined, args, data, interpreter);
184
+ return FunctionRuntimeImpl.customFunctions[funcName]._func.call(undefined, args, data, interpreter);
180
185
  }
181
186
  };
182
187
  return funcDef(...args, globals);
@@ -188,13 +193,13 @@ class FunctionRuntimeImpl {
188
193
  console.warn(`Unable to register function with name ${name}.`);
189
194
  return;
190
195
  }
191
- this.customFunctions[name] = finalFunction;
196
+ FunctionRuntimeImpl.customFunctions[name] = finalFunction;
192
197
  });
193
198
  }
194
199
  unregisterFunctions(...names) {
195
200
  names.forEach(name => {
196
- if (name in this.customFunctions) {
197
- delete this.customFunctions[name];
201
+ if (name in FunctionRuntimeImpl.customFunctions) {
202
+ delete FunctionRuntimeImpl.customFunctions[name];
198
203
  }
199
204
  });
200
205
  }
@@ -372,7 +377,9 @@ class FunctionRuntimeImpl {
372
377
  _signature: []
373
378
  }
374
379
  };
375
- return Object.assign(Object.assign({}, defaultFunctions), this.customFunctions);
380
+ return Object.assign(Object.assign({}, defaultFunctions), FunctionRuntimeImpl.customFunctions);
376
381
  }
377
382
  }
378
- exports.FunctionRuntime = new FunctionRuntimeImpl();
383
+ FunctionRuntimeImpl.instance = null;
384
+ FunctionRuntimeImpl.customFunctions = {};
385
+ exports.FunctionRuntime = FunctionRuntimeImpl.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.56",
3
+ "version": "0.22.58",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.56"
38
+ "@aemforms/af-formatters": "^0.22.58"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",