UNPKG

olympus-r

Version:

一个力求简单易用的前端开发框架 #### 开发语言 TypeScript #### 核心架构 MVC #### 模块间通讯和解耦 采用事件机制,利用一个全局唯一的事件派发器进行模块间通讯,解耦模块间依赖 #### 表现层结构 使用桥接模式拆分接口与实现,达到一套核心驱动多套表现层的目的(目前支持DOM、Egret、PixiJS三种表现层),同时支持表现层的未来可扩展性 #### TypeScript装饰器注入 框架提供TypeScript装饰器注入功能,便捷获取托管对象。例如:

140 lines (139 loc) 4.28 kB
import { core } from "../../core/Core"; import { engine, InitStep } from '../Engine'; import EngineMessage from "../message/EngineMessage"; import { system } from '../system/System'; /** * @author Raykid * @email initial_r@qq.com * @create date 2017-09-14 * @modify date 2017-09-14 * * Model的基类,也可以不继承该基类,因为Model是很随意的东西 */ var Model = /** @class */ (function () { function Model() { var _this = this; if (engine.initStep < InitStep.OpenFirstModule) { // Olympus还没初始化完成,等待之 core.listen(EngineMessage.INITIALIZED, this.onInitialized, this); } else { // Olympus已经初始化完毕,直接初始化 system.nextFrame(function () { _this.onInitialized(); }); } } Object.defineProperty(Model.prototype, "disposed", { /** * Model的disposed属性没有任何作用,仅为了实现接口,始终返回false * * @readonly * @type {boolean} * @memberof Model */ get: function () { return false; }, enumerable: true, configurable: true }); Object.defineProperty(Model.prototype, "observable", { /** * 转发core.observable * * @readonly * @type {IObservable} * @memberof Model */ get: function () { return core.observable; }, enumerable: true, configurable: true }); Object.defineProperty(Model.prototype, "parent", { /** * 获取到父级IObservable * * @type {IObservable} * @memberof Model */ get: function () { return null; }, enumerable: true, configurable: true }); /** * 在框架初始化完毕时调用 * * @memberof Model */ Model.prototype.onInitialized = function () { // 留待子类完善 }; Model.prototype.dispatch = function () { var params = []; for (var _i = 0; _i < arguments.length; _i++) { params[_i] = arguments[_i]; } core.dispatch.apply(core, params); }; /** * 监听内核消息 * * @param {string} type 消息类型 * @param {Function} handler 消息处理函数 * @param {*} [thisArg] 消息this指向 * @param {boolean} [once=false] 是否是一次性监听 * @memberof Model */ Model.prototype.listen = function (type, handler, thisArg, once) { if (once === void 0) { once = false; } core.listen(type, handler, thisArg, once); }; /** * 移除内核消息监听 * * @param {string} type 消息类型 * @param {Function} handler 消息处理函数 * @param {*} [thisArg] 消息this指向 * @param {boolean} [once=false] 是否是一次性监听 * @memberof Model */ Model.prototype.unlisten = function (type, handler, thisArg, once) { if (once === void 0) { once = false; } core.unlisten(type, handler, thisArg, once); }; /** * 注册命令到特定消息类型上,当这个类型的消息派发到框架内核时会触发Command运行 * * @param {string} type 要注册的消息类型 * @param {(ICommandConstructor)} cmd 命令处理器,可以是方法形式,也可以使类形式 * @memberof Model */ Model.prototype.mapCommand = function (type, cmd) { core.mapCommand(type, cmd); }; /** * 注销命令 * * @param {string} type 要注销的消息类型 * @param {(ICommandConstructor)} cmd 命令处理器 * @returns {void} * @memberof Model */ Model.prototype.unmapCommand = function (type, cmd) { core.unmapCommand(type, cmd); }; /** * Model的dispose方法没有任何作用,仅为了实现接口 * * @memberof Model */ Model.prototype.dispose = function () { }; return Model; }()); export default Model;