-
Notifications
You must be signed in to change notification settings - Fork 170
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
ER的两点疑问 #160
Comments
|
谢谢顾轶灵@Justineo ,第二个问题,我暂时没有疑问,先研究研究;回到第一个问题,我举了例子是想说明我的疑问:你们那样的设计是否有一些特别的考虑?
这样一些语句。 不知我是否表达清楚? 感谢~ |
你的问题主要在于 JS 没有原生的继承,这里的重复代码主要就是解决继承的问题。灰大 @otakustay 那边正在实验在项目中引入 ES6,通过 Babel 转译为浏览器可用的 JS,有了这个这些重复代码也许就可以简单地用 ES6 的继承来减少: class MyAction extends Action {
// override as needed
} |
补充一下,我们自己的项目里有脚手架来生成 Action/Model/View 的基本代码,所以其实开发业务的工程师也不需要关心这些。 |
简单地玩法下,不行。原因是如果你的代码中没有 复杂的玩法下,行,使用 function createMyActionFactory(baseName) {
return {
createRuntimeAction: window.require(
[baseName + 'Action', baseName + 'Model', baseName + 'View'],
function (Action, Model, View) {
var action = new Action;
action.model = new Model();
action.view = new View();
return action;
}
)
};
}
// 配置
var action = {
path: '/index',
type: createMyActionFactory('index')
};
require('er/controller').registerAction(action); 或者可以使用我们的uioc作依赖的管理,制作一个更通用的
er不会再提供这样的方式。er将定位玩MVC框架,语言相关的特性由eoo处理。 各个库/框架非常有针对性地完成自己的职责,使用不同的库/框架组合作为系统的基石,这是在npm等包管理系统盛行的今日Web应有的一个状态。 |
感谢@otakustay ,我明白你的意思了,我先研究研究,有问题再请教。 |
灰大 @otakustay ,我用了你说的 ActionFactory : function createMyActionFactory(baseName) {
return {
createRuntimeAction: window.require(
[baseName + 'Action', baseName + 'Model', baseName + 'View'],
function (Action, Model, View) {
var action = new Action;
action.model = new Model();
action.view = new View();
return action;
}
)
};
}
// 配置
var action = {
path: '/index',
type: createMyActionFactory('index')
};
require('er/controller').registerAction(action); 结果:console.log(" Error: TypeError: action.enter is not a function"); window.require(
[baseName + 'Action', baseName + 'Model', baseName + 'View'],
function (Action, Model, View) {
var action = new Action;
action.model = new Model();
action.view = new View();
return action;
}
) 这个会执行返回 action ,但此时已经抛出错误了。 |
灰大你这个例子里 |
@Justineo 顾轶灵,你的意思是: |
没错,我的代码是错的…需要返回promise,promise被resolve时参数是action实例
|
已找到答案,删除,哈哈~ |
我按照 ER DEMO 中的 book-store 例子,写了一个类似的例子,有一些疑问,
第一个是关于ER中Action,Model,View 实例创建方式的疑问:例如:
用上面的代码创建 Action 时,有两点:
第二,想问问 ER 与 ESUI 结合使用的例子,我看之前的 errorrik 写的 ER 中有一个 ui.js 中写了个 ui adapter ,将 ER 与 ESUI 结合了起来,那么,新版的 ER 可否采用相同的方式或者你们在实践中又是怎样处理的呢?
以上两个问题,感谢!
The text was updated successfully, but these errors were encountered: