采用新结构:Action*.js 从 node.server 中删除,集中存放于本库。

这样消除了同一份代码出现在两处的不良结构,避免了同步的困难。
当 node.server 需要临时修改 ActionXxx.js 时,只要在 server.js 里临时 require('../tic.action').ActionXxx 即可。一处修改,到处可用。
This commit is contained in:
luk.lu
2019-04-09 20:16:58 +08:00
parent e2a0738a80
commit 4fe26a0b09
6 changed files with 381 additions and 20 deletions

33
ActionStore.js Normal file
View File

@@ -0,0 +1,33 @@
const Action = require('./Action.js')
/** ****************** Public of instance ********************/
const DAD = module.exports = function ActionStore (prop) {
this._class = this.constructor.name
this.setProp(prop) // 没有定义 DAD.prototype._model因此继承了上级Action.prototype._model因此通过this.setProp继承了上级Action定义的实例自有数据。另一个方案是调用 Action.call(this, prop)
this.type = this.constructor.name
}
DAD.__proto__ = Action
// DAD._table=DAD.name // 注释掉从而继承父类Action的数据库表格名
const MOM = DAD.prototype
MOM.__proto__ = Action.prototype
/** ****************** Shared by instances ********************/
MOM.validateMe = function () {
// check size, account balance >= fee, fee>wo.Config.MIN_FEE_ActionStore
return this.fee >= wo.Config.MIN_FEE_ActionStore
}
MOM.executeMe = async function () {
let actor = await wo.Account.getOne({ Account: { address: this.actorAddress } })
if (actor && actor.balance >= this.fee) {
await actor.setMe({ Account: { balance: actor.balance - this.fee }, cond: { address: actor.address } }) // todo 20190409: change to use wo.Store
return this
}
return null
}
/** ****************** Public of class ********************/
DAD.api = {}