Skip to content

Commit

Permalink
feat: pass request to appContext hook
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Dec 6, 2023
1 parent edc50c4 commit 502a248
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/platform-shared/src/shared/application.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShuviRequest } from '@shuvi/service';
import { getManager, PluginManager } from './runtimPlugin';
import { initPlugins } from './runtimPlugin';
import { ModelPublicInstance, doura } from 'doura';
Expand All @@ -18,6 +19,7 @@ export class ApplicationImpl<Config extends {} = {}> {
private _router: IRouter;
private _appComponent: any;
private _pluginManager: PluginManager;
private _request?: ShuviRequest;
private _context: IAppContext;
private _config: Config;
private _store: Doura;
Expand All @@ -28,6 +30,7 @@ export class ApplicationImpl<Config extends {} = {}> {
constructor(options: ApplicationInternalOptions<Config>) {
this._config = options.config;
this._router = options.router;
this._request = options.request;
this._context = {} as IAppContext;
this._store = doura({ initialState: options.initialState });
this._error = this._store.getModel(errorModelName, errorModel);
Expand Down Expand Up @@ -110,7 +113,8 @@ export class ApplicationImpl<Config extends {} = {}> {

private async _initAppContext() {
await this._pluginManager.runner.appContext(this._context, {
router: this._router
router: this._router,
request: this._request
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/platform-shared/src/shared/applicationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Doura } from 'doura';
import { CustomAppContext } from '@shuvi/runtime';
import type { ShuviRequest } from '@shuvi/service';
import { IRouter } from './routerTypes';
import { IPluginList } from './runtimPlugin';
import { Loader } from './loader';
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface ApplicationInternalOptions<C extends {}> {
getLoaders: GetLoadersFn;
initialState?: IAppState;
plugins?: IPluginList;
request?: ShuviRequest;
}

export type ApplicationlOptions<C extends {}> = Omit<
Expand Down
2 changes: 2 additions & 0 deletions packages/platform-shared/src/shared/runtimPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IPluginHandlers,
HookMap
} from '@shuvi/hook';
import type { ShuviRequest } from '@shuvi/service';
import { CustomRuntimePluginHooks } from '@shuvi/runtime';
import { createPluginCreator } from '@shuvi/shared/plugins';
import { IAppContext } from './applicationTypes';
Expand All @@ -16,6 +17,7 @@ import { IRouter } from './routerTypes';
export type AppComponent = unknown;
export type AppContextCtx = {
router: IRouter;
request?: ShuviRequest;
};

const init = createAsyncParallelHook<void>();
Expand Down

0 comments on commit 502a248

Please sign in to comment.