Browse Source

Allow to dynamically add custom functions at runtime. This is very helpful for scenarios where the custom function is very domain-specific and does not make sense to add to the Luckysheet codebase.

Developer will have to be cognizant of locals and needs to handle providing the appropriate text based on the current locale.
master
Shlomo Morosow 3 years ago
parent
commit
31571b7230
  1. 3
      src/core.js
  2. 8
      src/function/functionlist.js

3
src/core.js

@ -126,6 +126,7 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.workbookCreateBefore = extendsetting.workbookCreateBefore; luckysheetConfigsetting.workbookCreateBefore = extendsetting.workbookCreateBefore;
luckysheetConfigsetting.workbookCreateAfter = extendsetting.workbookCreateAfter; luckysheetConfigsetting.workbookCreateAfter = extendsetting.workbookCreateAfter;
luckysheetConfigsetting.remoteFunction = extendsetting.remoteFunction; luckysheetConfigsetting.remoteFunction = extendsetting.remoteFunction;
luckysheetConfigsetting.customFunctions = extendsetting.customFunctions;
luckysheetConfigsetting.fireMousedown = extendsetting.fireMousedown; luckysheetConfigsetting.fireMousedown = extendsetting.fireMousedown;
luckysheetConfigsetting.forceCalculation = extendsetting.forceCalculation; luckysheetConfigsetting.forceCalculation = extendsetting.forceCalculation;
@ -156,7 +157,7 @@ luckysheet.create = function (setting) {
initPlugins(extendsetting.plugins , extendsetting.data); initPlugins(extendsetting.plugins , extendsetting.data);
// Store formula information, including internationalization // Store formula information, including internationalization
functionlist(); functionlist(extendsetting.customFunctions);
let devicePixelRatio = extendsetting.devicePixelRatio; let devicePixelRatio = extendsetting.devicePixelRatio;
if(devicePixelRatio == null){ if(devicePixelRatio == null){

8
src/function/functionlist.js

@ -3,10 +3,10 @@ import Store from '../store/index'
import locale from '../locale/locale'; import locale from '../locale/locale';
//{"0":"数学","1":"统计","2":"查找","3":"Luckysheet内置","4":"数据挖掘","5":"数据源","6":"日期","7":"过滤器","8":"财务","9":"工程计算","10":"逻辑","11":"运算符","12":"文本","13":"转换工具","14":"数组"} //{"0":"数学","1":"统计","2":"查找","3":"Luckysheet内置","4":"数据挖掘","5":"数据源","6":"日期","7":"过滤器","8":"财务","9":"工程计算","10":"逻辑","11":"运算符","12":"文本","13":"转换工具","14":"数组"}
const functionlist = function(){ const functionlist = function(customFunctions){
let _locale = locale(); let _locale = locale();
// internationalization,get function list // internationalization,get function list
let functionListOrigin = _locale.functionlist; let functionListOrigin = [..._locale.functionlist];
// add new property f // add new property f
for (let i = 0; i < functionListOrigin.length; i++) { for (let i = 0; i < functionListOrigin.length; i++) {
@ -14,6 +14,10 @@ const functionlist = function(){
func.f = functionImplementation[func.n]; func.f = functionImplementation[func.n];
} }
if (customFunctions) {
functionListOrigin.push(...customFunctions);
}
Store.functionlist = functionListOrigin; Store.functionlist = functionListOrigin;
// get n property // get n property

Loading…
Cancel
Save