Skip to content

Commit

Permalink
chore(core): add deprecate API (#4539)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev authored Jan 23, 2025
1 parent 22f7159 commit a104643
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 50 deletions.
58 changes: 25 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ Please read our [Code of Conduct](./CODE_OF_CONDUCT.md) before you join in the U

If you encounter any issues while using Univer, you can seek help in the following communities:

- [Discord community](https://discord.gg/z3NKNT6D2f)
- [GitHub Discussions](https://github.com/dream-num/univer/discussions)
- Join the Univer Chinese community (please scan the QR code [here](https://univer.ai/enterprises/#%E8%8E%B7%E5%8F%96%E5%95%86%E4%B8%9A%E7%89%88))
- [Discord community](https://discord.gg/z3NKNT6D2f)
- [GitHub Discussions](https://github.com/dream-num/univer/discussions)
- Join the Univer Chinese community (please scan the QR code [here](https://univer.ai/enterprises/#%E8%8E%B7%E5%8F%96%E5%95%86%E4%B8%9A%E7%89%88))

## Reporting Issues

If you encounter any issues or have any suggestions while using Univer, please feel free to raise them in the Github Issues. We will respond promptly.

To better assist you, we recommend:

- Before submitting an issue, please search to see if someone has already raised a similar question.
- We provide an [issue template](https://github.com/dream-num/univer/issues/new/choose) and encourage you to fill it out with sufficient information, which helps us quickly identify the problem.
- Please try to describe the issue in English, as it enables more people to participate in the discussion. We will also make an effort to reply in English to benefit a wider audience.
- Before submitting an issue, please search to see if someone has already raised a similar question.
- We provide an [issue template](https://github.com/dream-num/univer/issues/new/choose) and encourage you to fill it out with sufficient information, which helps us quickly identify the problem.
- Please try to describe the issue in English, as it enables more people to participate in the discussion. We will also make an effort to reply in English to benefit a wider audience.

> If you're new to submitting issues, we recommend to read [How To Ask Questions The Smart Way](http://www.catb.org/~esr/faqs/smart-questions.html) and [How to Report Bugs Effectively](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html) before posting. Well-written bug reports help us and help you!
Expand Down Expand Up @@ -58,7 +58,7 @@ Please refer to [Architecture](https://univer.ai/guides/sheet/architecture/unive

The structure of the repository is as follows:

```
```txt
.
├── common/ shared configuration and utilities
├── docs/ documentation
Expand All @@ -72,7 +72,7 @@ The structure of the repository is as follows:

The file structure of a plugin should be organized as follows:

```
```txt
|- common/
|- models/
|- services/
Expand All @@ -90,10 +90,10 @@ The file structure of a plugin should be organized as follows:

There are some limits on what paths could a file import from.

- common cannot import file in other folders
- models can only import files from common
- services can only import files from models and common
- commands can only import files from common, models and services
- common cannot import file in other folders
- models can only import files from common
- services can only import files from models and common
- commands can only import files from common, models and services

During the refactoring process, it is recommended to remove legacy folders such as `Enum`, `Interface`, `Basics`, and `Shared`.

Expand All @@ -103,7 +103,7 @@ Avoid creating barrel imports (index.ts) unless it is the main root index.ts fil

We added experimental support for mobile platforms since June 2024. After that, all UI plugins should split ui related code by their running platforms:

```
```txt
|- controllers/
|- render-controllers/
|- common/
Expand Down Expand Up @@ -138,8 +138,8 @@ Please refer to [Univer Naming Convention](./docs/NAMING_CONVENTION.md).

Before merging a pull request, please make sure the following requirements are met:

- All tests are passed. ESLint and Prettier errors are fixed.
- Test coverage is not decreased.
- All tests are passed. ESLint and Prettier errors are fixed.
- Test coverage is not decreased.

We provide preview deployments for pull requests. You can view the preview deployment by clicking the "Preview" link in the "View Deployment" section.

Expand Down Expand Up @@ -210,18 +210,17 @@ pnpm dev:libs

Univer uses Playwright to perform visual comparison tests. If you have made changes to the UI, the CI may fail due to visual differences. You can update the snapshots by running this GitHub Action [📸 Manually Update Snapshots · Workflow runs · dream-num/univer (github.com)](https://github.com/dream-num/univer/actions/workflows/update-snapshots-manually.yml) on your branch.


### Clean code

> Programs are meant to be ready by humans and only incidentally for computers to execute. - Harold Abelson
- Do not expose properties or methods those are not necessary to be exposed.
- Group related methods or properties together. Do not always use blank lines to separate them.
- Keep your concepts consistent by naming your variables consistently.
- Do not expose properties or methods those are not necessary to be exposed.
- Group related methods or properties together. Do not always use blank lines to separate them.
- Keep your concepts consistent by naming your variables consistently.

References:

* [Make your code readable](https://www.notonlycode.org/make-your-code-readable/)
- [Make your code readable](https://www.notonlycode.org/make-your-code-readable/)

### New Package

Expand All @@ -237,20 +236,13 @@ npm create @univerjs/cli init <project-name>
```

### How to Contribute to Facade API
#### Synchronous API Priority
* For asynchronous APIs, consider the following: Can a synchronous sub-API be extracted, separating logic such as secondary confirmation.
* For APIs that must be asynchronous, indicate this in the method name, such as `addCommentAsync`.

#### Chaining Principle
*. APIs must adhere to the chaining principle.
*. APIs with `modify` semantics should return `this`.
*. APIs with `create` semantics should return the created instance.
*. APIs with `delete` semantics should return `true/false`.

#### Easy to Get
*. All APIs/constants/enums should be accessible from the `univerAPI` variable.
Please refer to [How to Contribute to Facade API](./docs/CONTRIBUTING.md).

### Deprecate API

## Links
If you are going to deprecate an API, please follow the steps below:

* [How to Contribute to Facade API](./packages/facade/docs/CONTRIBUTING.md)
1. Mark the API as deprecated in the JSDoc, and use `{@link }` to refer to the new API.
2. In the implementation, call `deprecate` of `ILogService` to log a deprecation message.
3. Remove the API in the next minor version. If the API is considered heavily used, you can remove it in the next major version, e.g. 1.0.0.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# How to Contribute to Facade API

Facade API is an API layer of all other packages of Univer and it helps users to use Univer easily. For a detailed introduction of Facade API, please visit [Facade API](https://univer.ai/guides/sheet/facade/facade).

## How to Contribute
Facade API is an API layer of all other packages of Univer and it helps users to use Univer easily. For a detailed introduction of Facade API, please visit [Facade API](https://docs.univer.ai/en-US/guides/sheets/getting-started/facade).

Facade API is consists of multi classes such as `FUniver`, `FWorkbook` and `FRange` etc. You can refer to Google's [AppScripts](https://developers.google.com/apps-script/reference/spreadsheet) to design Facade API.

Expand Down Expand Up @@ -31,6 +29,24 @@ export class FWorkbook {
}
```

## Synchronous API Priority

- For asynchronous APIs, consider the following: Can a synchronous sub-API be extracted, separating logic such as secondary confirmation.
- For APIs that must be asynchronous, indicate this in the method name, such as `addCommentAsync`.

## Chaining Principle

APIs must adhere to the chaining principle:

- APIs with `modify` semantics should return `this`.
- APIs with `create` semantics should return the created instance.
- APIs with `delete` semantics should return `true/false`.

## Easy to Get

All APIs/constants/enums should be accessible from the `univerAPI` variable.

## Documentation

It is strongly suggested to add documentation for your code [here](https://github.com/dream-num/univer.ai/tree/dev/packages/community/src/content/docs/guides/sheet/facade). Please refer to our [documentation repo](https://github.com/dream-num/docs) for more guidance.

31 changes: 29 additions & 2 deletions packages/core/src/services/log/log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/* eslint-disable no-console */

import { createIdentifier } from '../../common/di';

import { Disposable } from '../../shared/lifecycle';

export enum LogLevel {
Expand All @@ -28,13 +27,17 @@ export enum LogLevel {
VERBOSE = 4,
}

// eslint-disable-next-line ts/no-explicit-any
type ArgsType = any[];

type ConsoleType = typeof console.log | typeof console.error | typeof console.warn | typeof console.debug;

export interface ILogService {
debug(...args: ArgsType): void;
log(...args: ArgsType): void;
warn(...args: ArgsType): void;
error(...args: ArgsType): void;
deprecate(...args: ArgsType): void;

setLogLevel(enabled: LogLevel): void;
}
Expand All @@ -43,6 +46,7 @@ export const ILogService = createIdentifier<ILogService>('univer.log');

export class DesktopLogService extends Disposable implements ILogService {
private _logLevel: LogLevel = LogLevel.INFO;
private _deduction = new Set<string>();

debug(...args: ArgsType): void {
if (this._logLevel >= LogLevel.VERBOSE) {
Expand All @@ -68,12 +72,18 @@ export class DesktopLogService extends Disposable implements ILogService {
}
}

deprecate(...args: ArgsType): void {
if (this._logLevel >= LogLevel.WARN) {
this._logWithDeduplication(console.error, ...args);
}
}

setLogLevel(logLevel: LogLevel): void {
this._logLevel = logLevel;
}

private _log(
method: typeof console.log | typeof console.error | typeof console.warn | typeof console.debug,
method: ConsoleType,
...args: ArgsType
): void {
const firstArg = args[0];
Expand All @@ -84,4 +94,21 @@ export class DesktopLogService extends Disposable implements ILogService {
method(...args);
}
}

private _logWithDeduplication(
method: ConsoleType,
...args: ArgsType
): void {
const hashed = hashLogContent(...args);
if (this._deduction.has(hashed)) {
return;
}

this._deduction.add(hashed);
this._log(method, ...args);
}
}

function hashLogContent(...args: ArgsType): string {
return args.map((a) => JSON.stringify(a)).join('');
}
24 changes: 12 additions & 12 deletions packages/find-replace/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ Overall, F&D is divided into many packages and works as plugins. This package (@

What does this package do?

- UI
- TODO: Some UI should be determined by business plugins?
- UI
- TODO: Some UI should be determined by business plugins?

What do business packages (e.g @univerjs/sheets-find-replace) do?

由 find-replace 包提供查找替换的调度服务、接口以及 UI,业务包提供具体的查找替换方法

- 输入查找内容
- 确定搜索范围,当前 focused 的业务,或者全部的业务
- 切换查找模式
- 接收各个业务提供的查找结果(可能需要支持动态查找)
- 定位查找项的位置
- 结束查找
- 执行替换或者全部替换
- 输入查找内容
- 确定搜索范围,当前 focused 的业务,或者全部的业务
- 切换查找模式
- 接收各个业务提供的查找结果(可能需要支持动态查找)
- 定位查找项的位置
- 结束查找
- 执行替换或者全部替换

各个包要做的事情

- 根据查找字符串的变化来搜索并把结果塞给 find-replace
- 查找高亮,定位到查找位置
- 执行替换 & re-update 查找结果
- 根据查找字符串的变化来搜索并把结果塞给 find-replace
- 查找高亮,定位到查找位置
- 执行替换 & re-update 查找结果

## Supported features in Jan 2024

Expand Down

0 comments on commit a104643

Please sign in to comment.