-
-
Notifications
You must be signed in to change notification settings - Fork 714
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
feat(formula): add register async function #4399
Conversation
View Deployment
|
Playwright test resultsDetails 21 tests across 10 suites |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #4399 +/- ##
=======================================
Coverage 33.28% 33.28%
=======================================
Files 2533 2533
Lines 130776 130854 +78
Branches 29170 29185 +15
=======================================
+ Hits 43525 43557 +32
- Misses 87251 87297 +46 ☔ View full report in Codecov by Sentry. |
packages/sheets-formula/src/services/register-function.service.ts
Outdated
Show resolved
Hide resolved
cbc13e0
to
722fefe
Compare
Origin Title: feat(formula): add register async function Title: feat(formula): add register async function close #xxx univerAPI.getFormula().registerFunction('HELLO', (name) => `Hello, ${name}!`, 'A simple greeting function');
// Use the function in a cell
univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1').setValue('World');
univerAPI.getActiveWorkbook().getActiveSheet().getRange('A2').setValue({ f: '=HELLO(A1)' });
// A2 will display: "Hello, World!" // Mock a user score fetching function univerAPI.getFormula().registerAsyncFunction('FETCH_USER_SCORE',
async (userId) => {
await new Promise(resolve => setTimeout(resolve, 1000));
// Mock fetching user score from database
return userId * 10 + Math.floor(Math.random() * 20);
},
{
description: 'customFunction.description.FETCH_USER_SCORE',
locales: {
'zhCN': {
'customFunction': {
'description': {
'FETCH_USER_SCORE': '从数据库中获取用户分数'
}
}
},
'enUS': {
'customFunction': {
'description': {
'FETCH_USER_SCORE': 'Mock fetching user score from database'
}
}
}
}
}
);
// Use in cell
univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1').setValue({ f: '=FETCH_USER_SCORE(42)' });
// After 1 second, A1 will display a score Pull Request Checklist
|
Good job |
close #xxx
// Mock a user score fetching function
Pull Request Checklist