Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

docs: add how to contribute to facade API (#1008)

Wenzhao Hufd579a78e543
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9133051f00..8e36d63c01 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -158,3 +158,7 @@ pnpm create @univerjs/cli init <project-name>
npm create @univerjs/cli init <project-name>
```
+
+## Links
+
+* [How to Contribute to Facade API](./packages/facade/docs/CONTRIBUTING.md)
\ No newline at end of file
diff --git a/packages/core/src/shared/lifecycle.ts b/packages/core/src/shared/lifecycle.ts
index 875a4e34db..2e400c9212 100644
--- a/packages/core/src/shared/lifecycle.ts
+++ b/packages/core/src/shared/lifecycle.ts
@@ -23,9 +23,11 @@ import type { Nullable } from '../common/type-utils';
import type { Observer } from '../observer/observable';
import { isObserver } from '../observer/observable';
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function toDisposable(observer: Nullable<Observer<any>>): IDisposable;
export function toDisposable(subscription: SubscriptionLike): IDisposable;
export function toDisposable(callback: () => void): IDisposable;
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function toDisposable(v: SubscriptionLike | (() => void) | Nullable<Observer<any>>): IDisposable {
let disposed = false;
@@ -107,8 +109,9 @@ export class Disposable implements IDisposable {
protected _disposed = false;
private readonly _collection = new DisposableCollection();
- protected disposeWithMe(disposable: IDisposable): IDisposable {
- return this._collection.add(disposable);
+ protected disposeWithMe(disposable: IDisposable | SubscriptionLike): IDisposable {
+ const d = isSubscription(disposable) ? toDisposable(disposable) : (disposable as IDisposable);
+ return this._collection.add(d);
}
dispose(): void {
diff --git a/packages/facade/docs/CONTRIBUTING.md b/packages/facade/docs/CONTRIBUTING.md
new file mode 100644
index 0000000000..da232d4f19
--- /dev/null
+++ b/packages/facade/docs/CONTRIBUTING.md
@@ -0,0 +1,36 @@
+# 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.work/guides/facade).
+
+## How to Contribute
+
+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.
+
+Please use JSDoc to document your code. For example:
+
+```typescript
+export class FWorkbook {
+ /**
+ * Get the active sheet of the workbook.
+ * @returns The active sheet of the workbook
+ */
+ getActiveSheet(): FWorksheet | null {
+ // ...
+ }
+
+ /**
+ * Create a new worksheet and returns a handle to it.
+ * @param name Name of the new sheet
+ * @param rows How may rows would the new sheet have
+ * @param column How many columns would the new sheet have
+ * @returns The new created sheet
+ */
+ create(name: string, rows: number, column: number): FWorksheet {
+ // ...
+ }
+}
+```
+
+## Documentation
+
+It is strongly suggested to add documentation for your code [here](https://github.com/dream-num/docs/tree/main/src/content/docs/guides/facade). Please refer to our [documentation repo](https://github.com/dream-num/docs) for more guidance.
diff --git a/tsconfig.json b/tsconfig.json
index 84f3636326..1bd5a649b3 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,7 +3,12 @@
"rootDir": ".",
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
- "lib": ["ESNext", "DOM", "WebWorker", "dom.iterable"],
+ "lib": [
+ "ESNext",
+ "DOM",
+ "WebWorker",
+ "dom.iterable"
+ ],
"target": "ESNext",
"module": "ESNext",
"experimentalDecorators": true,
@@ -21,7 +26,9 @@
"checkJs": false,
"skipLibCheck": true,
"isolatedModules": true,
- "types": ["node"]
+ "types": [
+ "node"
+ ]
},
"include": [],
"references": [