Skip to content
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(pivot): add mixin to util #3124

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/core/src/common/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ export abstract class UnitModel<_D = object, T extends UnitType = UnitType> exte
abstract name$: Observable<string>;
abstract setName(name: string): void;
}

interface IMixinProperty<T> {
// eslint-disable-next-line ts/no-explicit-any
[fnName: string]: (this: T, ...args: any[]) => any;
}

/**
* Mixin some methods to targetObject as prototype, the static methods will not be mixed in
* @param {T} targetClass The target class to mixin
* @param {IMixinProperty<T>} mixin The mixin object which contains the methods to mixin.
*/
export function mixinClass<T>(targetClass: T, mixin: IMixinProperty<T>): void {
for (const key in mixin) {
// eslint-disable-next-line no-prototype-builtins
if (mixin.hasOwnProperty(key)) {
// @ts-ignore
targetClass.prototype[key] = mixin[key];
}
}
}
2 changes: 1 addition & 1 deletion packages/facade/src/apis/sheets/f-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FWorkbook {

constructor(
private readonly _workbook: Workbook,
@Inject(Injector) private readonly _injector: Injector,
@Inject(Injector) protected readonly _injector: Injector,
@Inject(IResourceLoaderService) private readonly _resourceLoaderService: IResourceLoaderService,
@Inject(SheetsSelectionsService) private readonly _selectionManagerService: SheetsSelectionsService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
Expand Down
Loading