Giter Site home page Giter Site logo

dva-ast's People

Contributors

chrisfan avatar jaredleechn avatar sorrycc avatar vale1534 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dva-ast's Issues

api: 完成 routeComponents

接口列表:

  • create
  • remove
  • ...

完成后:

  • 补全接口说明(主要是参数,filePathsourcePath 每个必传,不必重复描述)

在生成的代码中使用单引号代替双引号,或新增配置可由使用者定义

目前在生成的代码中,存在双引号。

如:models.create 在定义了 entry 时,会在 entry 中新增对于 model 的引用

app.model(require("./model/name")

该语句中存在双引号,在配置了以单引号作为引号类型的lint规则下会抛错

建议做一个全局配置,引号的类型可由使用者定义,并且默认引号类型为单引号。如:

import { config } from 'dva-ast'

config({
  quoteType: 'single'|'double'
})

支持非默认的 reducers 和 effects

TODO:

  • reducers with enhancer
  • effect with type

比如:

app.model({
  reducers: [{}, enhancer],
  effects: {
    addRemoteLatest: [function*() {}, { type: 'takeLatest' }],
  },
});

reducer and effect enhancement

reducerByIds: [{
  namespace,
  name,
}]

这里 namespace 就是 model 的 namespace,name 就是 effect 的 action type

这个是放在 selector 里面处理好一些还是放在 dva-ast 处理好?

namespace Literal 检查

  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;
    });
  },

api: 完成 models 的实现

接口列表:

  • 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 })

完成后:

  • 补全接口说明(主要是参数,filePathsourcePath 每个必传,不必重复描述)

dva-ast api design

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

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: [
    ...,
  ],
}

XNode.save

const userModel = ...;
delete userModel.effects['users/query'];
userModel.save();

update the source file.

api: 完成 router

接口列表:

  • create
  • remove
  • ...

完成后:

  • 补全接口说明(主要是参数,filePathsourcePath 每个必传,不必重复描述)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.