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(network): network plugin support overrides #3870

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
18 changes: 15 additions & 3 deletions packages/network/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,39 @@
* limitations under the License.
*/

import { Inject, Injector, Plugin, registerDependencies } from '@univerjs/core';
import type { DependencyOverride } from '@univerjs/core';
import { Inject, Injector, mergeOverrideWithDependencies, Plugin, registerDependencies } from '@univerjs/core';
import { HTTPService } from './services/http/http.service';
import { IHTTPImplementation } from './services/http/implementations/implementation';
import { XHRHTTPImplementation } from './services/http/implementations/xhr';

export interface IUniverNetworkPluginConfig {
/**
* Build in dependencies that can be overridden:
*
* - {@link HTTPService}
* - {@link IHTTPImplementation}
*/
override?: DependencyOverride;
}

/**
* This plugin add network services to the Univer instance.
*/
export class UniverNetworkPlugin extends Plugin {
static override pluginName = 'UNIVER_NETWORK_PLUGIN';

constructor(
private readonly _config: Partial<IUniverNetworkPluginConfig> | undefined = undefined,
@Inject(Injector) protected readonly _injector: Injector
) {
super();
}

override onStarting(): void {
registerDependencies(this._injector, [
registerDependencies(this._injector, mergeOverrideWithDependencies([
[HTTPService],
[IHTTPImplementation, { useClass: XHRHTTPImplementation }],
]);
], this._config?.override));
}
}
Loading