Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Veron
    @joriewong
    {
    "entry": "src/index.js",
    "env": {
    "development": {
    "extraBabelPlugins": [
    "dva-hmr",
    "transform-runtime",
    ["import", {"libraryName": "antd", "style": "css"}]
    ]
    },
    "production": {
    "extraBabelPlugins": [
    "transform-runtime",
    ["import", {"libraryName": "antd", "style": "css"}]
    ]
    }
    },
    "proxy": {
    "/api": {
    "target": "http://",
    "changeOrigin": true,
    "pathRewrite": {"^/api": ""}
    }
    }
    }
    17
    @miss61008596
    cd /node_moudules/dva/ 然后 1 step: npm i; 2 step: npm i -g ruban; 3 step: node_moudules/dva/lib 中出现转码后的文件,但是转码后的文件 和lib里的自带原始文件不同,而且不能正常 运行项目
    17
    @miss61008596
    "dva": "^2.1.0",
    17
    @miss61008596
    model global.js
    *changeLocale({
          payload
        },{ put, call, select }) {
          let signupFlagTemp1 = yield select(state => state.global.appLocale);
          console.log(signupFlagTemp1);
          console.log("changeLocale click");
          console.log("payload: ",payload);
          yield put ({
            type: 'saveAppLocale',
            payload: payload
    
          });
          let signupFlagTemp2 = yield select(state => state.global.appLocale);
          console.log(signupFlagTemp2);
        }
    我在 dva/src/index.js 里面加入 这些代码 可以在 models 加入state.global.appLocale来控制所有子组件的 国际化么?
    function App({dispatch, appLocale, children}) {
      return (
        <LocaleProvider locale={appLocale}>
          {children}
        </LocaleProvider>
      );
    }
    
    function mapStateToProps(state) {
      const {appLocale} = state.global;
      return {
        loading: state.loading.models.global,
        appLocale
      };
    }
    
    var CApp = require('react-redux').connect(mapStateToProps)(App);
    
    function getProvider(store, app, router) {
      return extraProps => (
        <Provider store={store}>
          <CApp>
            { router({app, history: app._history, ...extraProps}) }
          </CApp>
        </Provider>
      );
    }

    cd /node_moudules/dva/ 然后 1 step: npm i; 2 step: npm i -g ruban; 3 step: node_moudules/dva/lib 中出现转码后的文件,但是转码后的文件 和lib里的自带原始文件不同,而且不能正常 运行项目

    原始自带文件/node_moudules/dva/ lib/index.js

    'use strict';
    
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    
    var _extends2 = require('babel-runtime/helpers/extends');
    
    var _extends3 = _interopRequireDefault(_extends2);
    
    var _typeof2 = require('babel-runtime/helpers/typeof');
    
    var _typeof3 = _interopRequireDefault(_typeof2);
    
    var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
    
    var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
    
    exports.default = function () {
      var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    
      var history = opts.history || (0, _createHashHistory2.default)();
      var createOpts = {
        initialReducer: {
          routing: _reactRouterRedux.routerReducer
        },
        setupMiddlewares: function setupMiddlewares(middlewares) {
          return [(0, _reactRouterRedux.routerMiddleware)(history)].concat((0, _toConsumableArray3.default)(middlewares));
        },
        setupApp: function setupApp(app) {
          app._history = patchHistory(history);
        }
      };
    
      var app = core.create(opts, createOpts);
      var oldAppStart = app.start;
      app.router = router;
      app.start = start;
      return app;
    
      function router(router) {
        (0, _invariant2.default)((0, _utils.isFunction)(router), '[app.router] router should be function, but got ' + (typeof router === 'undefined' ? 'undefined' : (0, _typeof3.default)(router)));
        app._router = router;
      }
    
      function start(container) {
        // 允许 container 是字符串,然后用 querySelector 找元素
        if (isString(container)) {
          container = _document2.default.querySelector(container);
          (0, _invariant2.default)(container, '[app.start] container ' + container + ' not found');
        }
    
        // 并且是 HTMLElement
        (0, _invariant2.default)(!container || isHTMLElement(container), '[app.start] container should be HTMLElement');
    
        // 路由必须提前注册
        (0, _invariant2.default)(app._router, '[app.start] router must be registered before app.start()');
    
        oldAppStart.call(app);
        var store = app._store;
    
        // export _getProvider for HMR
        // ref: https://github.com/dvajs/dva/issues/469
        app._getProvider = getProvider.bind(null, store, app);
    
        // If has container, render; else, return react component
        if (container) {
          render(container, store, app, app._router);
          app._plugin.apply('onHmr')(render.bind(null, container, store, app));
        } else {
          return getProvider(store, this, this._router);
        }
      }
    };
    
    var _react = require('react');
    
    var _react2 = _interopRequireDefault(_react);
    
    var _invariant = require('invariant');
    
    var _invariant2 = _interopRequireDefault(_invariant);
    
    var _createHashHistory = require('history/createHashHistory');
    
    var _createHashHistory2 = _interopRequireDefault(_createHashHistory);
    
    var _reactRouterRedux = require('react-router-redux');
    
    var _document = require('global/document');
    
    var _document2 = _interopRequireDefault(_document);
    
    var _reactRedux = require('react-redux');
    
    var _dvaCore = require('dva-core');
    
    var core = _interopRequireWildcard(_dvaCore);
    
    var _utils = require('dva-core/lib/utils');
    
    function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
    
    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
    
    function isHTMLElement(node) {
      return (typeof node === 'undefined' ? 'undefined' : (0, _typeof3.default)(node)) === 'object' && node !== null && node.nodeType && node.nodeName;
    }
    
    function isString(str) {
      return typeof str === 'string';
    }
    
    function getProvider(store, app, router) {
      return function (extraProps) {
        return _react2.default.createElement(
          _reactRedux.Provider,
          { store: store },
          router((0, _extends3.default)({ app: app, history:
    * 编译后的文件
    "use strict";
    
    var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
    
    var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
    
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = _default;
    
    var _jsx2 = _interopRequireDefault(require("@babel/runtime/helpers/jsx"));
    
    var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
    
    var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
    
    var _react = _interopRequireDefault(require("react"));
    
    var _invariant = _interopRequireDefault(require("invariant"));
    
    var _createHashHistory = _interopRequireDefault(require("history/createHashHistory"));
    
    var _reactRouterRedux = require("react-router-redux");
    
    var _document = _interopRequireDefault(require("global/document"));
    
    var _reactRedux = require("react-redux");
    
    var core = _interopRequireWildcard(require("dva-core"));
    
    var _utils = require("dva-core/lib/utils");
    
    function _default() {
      var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var history = opts.history || (0, _createHashHistory.default)();
      var createOpts = {
        initialReducer: {
          routing: _reactRouterRedux.routerReducer
        },
        setupMiddlewares: function setupMiddlewares(middlewares) {
          return [(0, _reactRouterRedux.routerMiddleware)(history)].concat((0, _toConsumableArray2.default)(middlewares));
        },
        setupApp: function setupApp(app) {
          app._history = patchHistory(history);
        }
      };
      var app = core.create(opts, createOpts);
      var oldAppStart = app.start;
      app.router = router;
      app.start = start;
      return app;
    
      function router(router) {
        (0, _invariant.default)((0, _utils.isFunction)(router), "[app.router] router should be function, but got ".concat(typeof router));
        app._router = router;
      }
    
      function start(container) {
        // 允许 container 是字符串,然后用 querySelector 找元素
        if (isString(container)) {
          container = _document.default.querySelector(container);
          (0, _invariant.default)(container, "[app.start] container ".concat(container, " not found"));
        } // 并且是 HTMLElement
    
    
        (0, _invariant.default)(!container || isHTMLElement(container), "[app.start] container should be HTMLElement"); // 路由必须提前注册
    
        (0, _invariant.default)(app._router, "[app.start] router must be registered before app.start()");
        oldAppStart.call(app);
        var store = app._store; // export _getProvider for HMR
        // ref: https://github.com/dvajs/dva/issues/469
    
        app._getProvider = getProvider.bind(null, store, app); // If has container, render; else, return react component
    
        if (container) {
          render(container, store, app, app._router);
    
          app._plugin.apply('onHmr')(render.bind(null, container, store, app));
        } else {
          return getProvider(store, this, this._router);
        }
      }
    }
    
    function isHTMLElement(node) {
      return typeof node === 'object' && node !== null && node.nodeType && node.nodeName;
    }
    
    function isString(str) {
      return typeof str === 'string';
    }
    
    function getProvider(store, app, router) {
      return function (extraProps) {
        return (0, _jsx2.default)(_reactRedux.Provider, {
          store: store
        }, void 0, router((0, _extends2.default)({
          app: app,
          history: app._history
        }, extraProps)));
      };
    }
    
    function render(container, store, app, router) {
      var ReactDOM = require('react-dom'); // eslint-disable-line
    
    
      ReactDOM.render(_react.default.createElement(getProvider(store, app, router)), container);
    }
    
    function patchHistory(history) {
      var oldListen = history.listen;
    
      history.listen = function (callback) {
        callback(history.location);
        return oldListen.call(history, callback);
      };
    
      return history;
    }
    
    module.exports = exports["default"];
    17
    @miss61008596
    然后 运行npm run build:dll 失败
    zhubogongdeMBP:aimarket_web zhubg$ npm run build:dll
    
    > aimarket_web@0.0.1 build:dll /Users/zhubg/ATMatrixProjects/aimarket_web
    > roadhog buildDll
    
    Creating dll bundle...
    Failed to compile.
    
    Module not found: Error: Can't resolve '@babel/runtime/helpers/extends' in '/Users/zhubg/ATMatrixProjects/aimarket_web/node_modules/dva/lib'
    
    Module not found: Error: Can't resolve '@babel/runtime/helpers/interopRequireDefault' in '/Users/zhubg/ATMatrixProjects/aimarket_web/node_modules/dva/lib'
    
    Module not found: Error: Can't resolve '@babel/runtime/helpers/interopRequireWildcard' in '/Users/zhubg/ATMatrixProjects/aimarket_web/node_modules/dva/lib'
    
    Module not found: Error: Can't resolve '@babel/runtime/helpers/jsx' in '/Users/zhubg/ATMatrixProjects/aimarket_web/node_modules/dva/lib'
    
    Module not found: Error: Can't resolve '@babel/runtime/helpers/toConsumableArray' in '/Users/zhubg/ATMatrixProjects/aimarket_web/node_modules/dva/lib'
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! aimarket_web@0.0.1 build:dll: `roadhog buildDll`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the aimarket_web@0.0.1 build:dll script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/zhubg/.npm/_logs/2017-12-11T10_18_37_692Z-debug.log
    zhubogongdeMBP:aimarket_web zhubg$
    我就是想用 store 里的 state.global.appLocale 来在app的任何地方 都可以 改变app的语言,
        dispatch({
          type: 'global/changeLocale',
          payload: {appLocale: enUS}
        });
    请大家帮忙
    Veron
    @joriewong
    %MO)S3CRU$KK9QO~0IEL}~4.png
    请问红框的地方为什么用bind呀?
    ChrisF
    @ChrisFerrell
    any info on dva, typescript, and whether hot module replacement with typescript and dva. I'm assuming you'd have to use awesome-typescript-loader to produce es6 and then go through babel. Was thinking about moving off of standard redux and going to dva or mobx-tree-state
    Veron
    @joriewong
    想请问一下
    React中父子均为无状态组件
    如何实现组件间传值
    linyongping
    @linyongping
    @joriewong 传到redux
    Veron
    @joriewong
    麻烦大家有空的时候可以帮忙解答一下
    Thomas Bereczky
    @SysOpsNet
    Hey There
    Does anyone have a good example of using DVA with React Router v4?
    Alexey Elizarov
    @beautyfree
    Hey, please publish dva-core with type fix
    Tun Tun Aung
    @tunaung2048

    请问一下
    大家用什么backend跟dva?
    我用的是feathersJS.
    如何用dva跟feathersJS项目团在一个包子里

    /src
    .. server/
    .. client/dva-prj

    Tun Tun Aung
    @tunaung2048
    那就开发时可以用 npm start 就可以起动 client and server 了。
    Thomas Bereczky
    @SysOpsNet
    Hey Guys
    is there anyone around I could hire for a couple of hours ?
    full
    @sunshinefull
    express 怎么获取前端传来的request payload 里面的值
    Bruce Sun
    @athrunsun
    umi跟dva是什么关系呢?umi是dva的带同构渲染的替代品?
    Veron
    @joriewong
    请问如果是离线react、react-dom要怎么引入呢?
    Veron
    @joriewong
    <script src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"></script>
    <script>!window.React && document.write("<script src=\"react.production.min.js\">" + "<\/script>")</script>
    <script src="https://unpkg.com/react-dom@16.0.0/umd/react-dom.production.min.js"></script>
    <script>!window.ReactDOM && document.write("<script src=\"react-dom.production.min.js\">" + "<\/script>")</script>
    Sisir
    @prionkor
    hi, I am new to dvajs. Building my first app. Have to say. it really saves a lot of time and less learning curve..
    BIG thanks to the team. Really appreciate it!! <3 :)
    Sisir
    @prionkor
    Is it possible to access global state from reducer? The state passed in reducer is the props under the namespace..
    Sisir
    @prionkor
    Hello, can anyone help me with persisted state loading into dva app? Here is the details https://stackoverflow.com/questions/52936186/dvajs-load-saved-state-from-localstorage-into-state Appreciate your help!
    cheng0726
    @zhilianbi520
    dva配合redux-persist 如何使用?
    Sisir
    @prionkor
    Could you use english?
    Sisir
    @prionkor
    I like dvajs very much, but there is no support, no help on learning curve at all..
    starting to think If I am wasting my time..
    原罪
    @fwh1990
    Does dvajs support typescript? If no, then I found a package named redux-model-ts, with 100% type checking.