dvajs / dva-ast Goto Github PK
View Code? Open in Web Editor NEWdva static analysis based on javascript ast.
License: MIT License
dva static analysis based on javascript ast.
License: MIT License
目前在生成的代码中,存在双引号。
如:models.create
在定义了 entry 时,会在 entry 中新增对于 model 的引用
app.model(require("./model/name")
该语句中存在双引号,在配置了以单引号作为引号类型的lint规则下会抛错
建议做一个全局配置,引号的类型可由使用者定义,并且默认引号类型为单引号。如:
import { config } from 'dva-ast'
config({
quoteType: 'single'|'double'
})
findModels(namespace) {
return this.find(j.ObjectExpression, node => {
const props = node.properties.reduce((memo, prop) => {
if (j.Property.check(prop)) {
if (prop.key.name === 'namespace') {
// 此处是否多余,如果不是 Literal,就直接跳过?
assert(
j.Literal.check(prop.value),
`findModels: namespace should be Literal, but got ${prop.value.type}`
);
memo[prop.key.name] = prop.value.value;
} else {
memo[prop.key.name] = true;
}
}
return memo;
}, {});
if (!props.namespace) return false;
if (namespace && props.namespace !== namespace) return false;
// state 不是必须的
// 但为增加准确性, 还需要声明除 namespace 以外的其他任一项
return props.state ||
props.reducers ||
props.effects ||
props.subscriptions;
});
},
发布到 npm 上的这个包,没有 compile,编译的时候报错 0.0 @ChrisFan
接口列表:
create({ namespace })
remove({ namespace })
updateNamespace({ namespace, newNamespace })
updateState({ namespace, source })
addReducer({ namespace, [source] })
updateReducer({ namespace, source })
removeReducer({ namespace })
addEffect({ namespace, [source] })
updateEffect({ namespace, source })
removeEffect({ namespace })
addSubscription({ namespace, [source] })
updateSubscription({ namespace, source })
removeSubscription({ namespace })
完成后:
filePath
和 sourcePath
每个必传,不必重复描述)https://github.com/dvajs/dva-ast/blob/master/dva-projects/user-dashboard/src/models/users.js#L21
这里的 (dispatch)
要换成 ({ dispatch })
。
待核实
core apis, the idea is to offers the abilities of get infrastructure data from the source code and write back after you updated these data.
require('dav-ast').parse(
[path],
{options}
)
return an object which describes the dva infrastructure about your app,
{
$$node: <XNode>,
models: [
{
$$node: <XNode>,
namespace: 'user',
state: {
list: [],
loading: false,
total: null,
},
subscriptions: [
'function (dispatch) {\n...',
],
effects: {
'users/query': 'function ...',
'users/delete': '...'
'users/create': '...',
'users/update': '...',
},
reducers: {
...
},
}
],
containers: [
...,
],
}
const userModel = ...;
delete userModel.effects['users/query'];
userModel.save();
update the source file.
苦苦的 Windows 10 用户,期望生成的代码是 ‘LF’ 结尾的。
备注:我用 dva-cli 。
现在取到的 routeComponents 包含了所有的 components,要根据 router 配置进行区分。
接口列表:
create
remove
完成后:
filePath
和 sourcePath
每个必传,不必重复描述)TODO:
比如:
app.model({
reducers: [{}, enhancer],
effects: {
addRemoteLatest: [function*() {}, { type: 'takeLatest' }],
},
});
When jscodeshift upgrades to v0.3.32
, the following call would cause bugs:
Collection.fromPaths([], this);
Please check it!
See: dvajs/dva-cli#91
Related: #21
reducerByIds: [{
namespace,
name,
}]
这里 namespace 就是 model 的 namespace,name 就是 effect 的 action type
这个是放在 selector 里面处理好一些还是放在 dva-ast 处理好?
app.model(require('path/to/created/model'));
接口列表:
create
remove
完成后:
filePath
和 sourcePath
每个必传,不必重复描述)A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.