-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d577627
commit fa4f19c
Showing
10 changed files
with
562 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Engine } from "./engine"; | ||
|
||
// 控制器,负责处理业务逻辑,并处理数据模型和view的交互(MVC中的C) | ||
export default abstract class Controller { | ||
|
||
/** 设置了name的Controller可以被替换 */ | ||
getName(): string | void { | ||
} | ||
|
||
apply(engine: Engine, controller: Controller) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
export { default as CoreEngine } from './engine' | ||
export { default as Plugin } from './plugin' | ||
import Tanfu, { Plugin, GLOBAL_ELEMENTS_KEY } from "./tanfu"; | ||
import CoreEngine, { Engine } from "./engine"; | ||
import Controller from "./controller"; | ||
export default Tanfu | ||
export { | ||
CoreEngine, | ||
Engine, | ||
Controller, | ||
Plugin, | ||
GLOBAL_ELEMENTS_KEY | ||
} | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Controller from "./controller" | ||
import CoreEngine from "./engine" | ||
|
||
// 函数式插件 | ||
type PluginFunction = () => void | ||
// 对象式插件 | ||
type PluginObject = { install: () => void } | ||
// 插件 | ||
export type Plugin = PluginFunction | PluginObject | ||
// 存储全局元素 | ||
const globalElements: Record<string, any> = {} | ||
|
||
export const GLOBAL_ELEMENTS_KEY = '__$_TANFU_GLOBAL_ELEMENTS_$__' | ||
|
||
export interface Tanfu { | ||
Controller: typeof Controller; | ||
CoreEngine: typeof CoreEngine; | ||
/** 使用插件 */ | ||
use: (plugin: Plugin) => void; | ||
/** 注册元素 */ | ||
element: (elementId: string, ui: any) => void; | ||
/** 设置controller的原型 */ | ||
setPrototypeOfController: (key: string, value: any) => void | ||
} | ||
|
||
const tanfu: Tanfu = { | ||
Controller, | ||
CoreEngine, | ||
use(plugin: Plugin) { | ||
if (typeof plugin === 'function') plugin() | ||
else plugin?.install() | ||
}, | ||
element(elementId, ui) { | ||
globalElements[elementId] = ui | ||
}, | ||
setPrototypeOfController(key, value) { | ||
//@ts-ignore | ||
Controller.prototype[key] = value | ||
}, | ||
|
||
/** | ||
* 全局组件注册,不建议外部使用 | ||
*/ | ||
// @ts-ignore | ||
[GLOBAL_ELEMENTS_KEY]: globalElements | ||
} | ||
|
||
|
||
export default tanfu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.