Skip to content

Commit

Permalink
fix: delete hooks file
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Apr 28, 2021
1 parent 2e3e3b2 commit 1778efc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 136 deletions.
4 changes: 2 additions & 2 deletions packages/runtime/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'reflect-metadata';
import { Plugin } from './utils/hooks';
import { Garfish } from './instance/context';
import { assert, warn } from '@garfish/utils';
export { Plugin, Lifecycle } from './utils/hooks';
export { Plugin, Lifecycle } from './plugin/hooks';
import CjsExternal from '@garfish/cjs-external';

declare global {
Expand Down Expand Up @@ -37,6 +36,7 @@ async function use() {

use();

console.log(GarfishInstance);
// GarfishInstance.run();

export default Garfish;
11 changes: 7 additions & 4 deletions packages/runtime/core/src/instance/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, Hooks, hooks } from '../utils/hooks';
import { Plugin, Hooks, hooks } from '../plugin/hooks';
import { getDefaultOptions } from '../config';
import { Options, AppInfo, LoadAppOptions } from '../type';
import {
Expand All @@ -13,7 +13,6 @@ import {
import { Loader } from '../module/loader';
import { getRenderNode } from '../utils';


export class Garfish {
public version = __VERSION__;
private running = false;
Expand All @@ -39,7 +38,11 @@ export class Garfish {
hooks.lifecycle.initialize.call(this, this.options);
}

public usePlugin(plugin: (context: Garfish) => Plugin, context: Garfish, ...args: Array<any>) {
public usePlugin(
plugin: (context: Garfish) => Plugin,
context: Garfish,
...args: Array<any>
) {
assert(typeof plugin === 'function', 'Plugin must be a function.');
if ((plugin as any)._registered) {
__DEV__ && warn('Please do not register the plugin repeatedly.');
Expand Down Expand Up @@ -118,7 +121,7 @@ export class Garfish {
if (!appInfo) {
appInfo = { cache: true, ...opts };
}
appInfo.domGetter = getRenderNode(appInfo.domGetter)
appInfo.domGetter = getRenderNode(appInfo.domGetter);

const asyncLoadProcess = async () => {
// Return not undefined type data directly to end loading
Expand Down
8 changes: 0 additions & 8 deletions packages/runtime/core/src/ioc/container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import getDecorators from 'inversify-inject-decorators';
import { Container, tagged, named } from 'inversify';
import { Hooks } from '../plugin/hooks';
import { Loader } from '../module/loader';
// import { Garfish } from "../instance/context";

export const container = new Container();
Expand All @@ -10,14 +8,8 @@ export const lazyInject = decorators.lazyInject;

export const TYPES = { Loader: 'Loader', Hooks: 'Hooks', Garfish: 'Garfish' };

container.bind<Hooks>(TYPES.Hooks).to(Hooks).inRequestScope();
container.bind<Loader>(TYPES.Loader).to(Loader).inRequestScope();
// container.bind<Garfish>(TYPES.Garfish).toConstructor(Garfish);

export { Hooks } from '../plugin/hooks';
export { Loader } from '../module/loader';
export { injectable, inject } from 'inversify';

// export function injectable (){
// return function (target) {

Expand Down
35 changes: 14 additions & 21 deletions packages/runtime/core/src/module/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
VText,
warn,
} from '@garfish/utils';
import { hooks } from '../utils/hooks';
import { hooks } from '../plugin/hooks';
import { createAppContainer, getRenderNode } from '../utils';
import { renderContainer } from './htmlRender'
import { renderContainer } from './htmlRender';
import { HtmlResource } from './source';

const __GARFISH_EXPORTS__ = '__GARFISH_EXPORTS__';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class App {
appInfo: AppInfo,
entryResManager: HtmlResource,
resources: ResourceModules,
isHtmlMode: boolean
isHtmlMode: boolean,
) {
this.appInfo = appInfo;
this.name = appInfo.name;
Expand All @@ -94,26 +94,26 @@ export class App {
url?: string,
options?: { async?: boolean; noEntry?: boolean },
) {
hooks.lifecycle.beforeEval.call('',this.appInfo, code, env, url, options);
hooks.lifecycle.beforeEval.call('', this.appInfo, code, env, url, options);
const sourceUrl = url ? `//# sourceURL=${url}\n` : '';

// execEnv
if (!env) {
env = options?.noEntry
? { [__GARFISH_EXPORTS__]: this.customExports }
: this.cjsModules;
? { [__GARFISH_EXPORTS__]: this.customExports }
: this.cjsModules;
}

try {
evalWithEnv(`;${code}\n${sourceUrl}`, env);
} catch (e) {
hooks.lifecycle.errorExecCode.call('',this.appInfo,e);
hooks.lifecycle.errorExecCode.call('', this.appInfo, e);
throw e;
}
hooks.lifecycle.afterEval.call('',this.appInfo, code, env, url, options);
hooks.lifecycle.afterEval.call('', this.appInfo, code, env, url, options);
}

private canMount (){
private canMount() {
// If you are not in mount mount
if (this.mounting) {
__DEV__ && warn(`The ${this.appInfo.name} app mounting.`);
Expand Down Expand Up @@ -156,10 +156,9 @@ export class App {
this.callRender(provider);

hooks.lifecycle.afterMount.call('', this.appInfo);

} catch(err) {
} catch (err) {
removeElement(this.appContainer);
hooks.lifecycle.errorMount.call('',this.appInfo,err);
hooks.lifecycle.errorMount.call('', this.appInfo, err);
} finally {
this.mounting = false;
}
Expand Down Expand Up @@ -347,24 +346,18 @@ export class App {
);
}

private execAsyncScript () {
let { resources } = this;
private execAsyncScript() {
const { resources } = this;
// If you don't want to use the CJS export, at the entrance is not can not pass the module, the require
// this.execScript('console.log()');


for (const manager of resources.js) {
console.log(manager);
}
}

private async checkAndGetProvider() {
const {
appInfo,
rootElement,
cjsModules,
customExports,
} = this;
const { appInfo, rootElement, cjsModules, customExports } = this;
const { props, basename } = appInfo;
let provider = (cjsModules.exports && cjsModules.exports.provider) as
| Provider
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/core/src/plugin/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AsyncParallelBailHook,
AsyncSeriesHook,
} from '@garfish/hooks';
import { injectable } from 'inversify';
import { Garfish } from '../instance/context';
import { injectable } from '../ioc/container';
import { Options, AppInfo, LoadAppOptions } from '../type';

export function keys<O>(o: O) {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/core/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Garfish } from './instance/context';
import { Plugin } from './utils/hooks';
import { Plugin } from './plugin/hooks';

export type DomGetter = Element | (() => Element | null) | string;

Expand Down
99 changes: 0 additions & 99 deletions packages/runtime/core/src/utils/hooks.ts

This file was deleted.

0 comments on commit 1778efc

Please sign in to comment.