Socket
Socket
Sign inDemoInstall

dva

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dva - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0-beta.1

88

lib/dynamic.js

@@ -19,6 +19,28 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
exports.default = dynamic;
var _reactAsyncComponent = require('react-async-component');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -34,2 +56,64 @@

function asyncComponent(config) {
var resolve = config.resolve;
return function (_Component) {
(0, _inherits3.default)(DynamicComponent, _Component);
function DynamicComponent() {
var _ref;
(0, _classCallCheck3.default)(this, DynamicComponent);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = (0, _possibleConstructorReturn3.default)(this, (_ref = DynamicComponent.__proto__ || (0, _getPrototypeOf2.default)(DynamicComponent)).call.apply(_ref, [this].concat(args)));
_this.LoadingComponent = config.LoadingComponent || function () {
return null;
};
_this.state = {
AsyncComponent: null
};
_this.load();
return _this;
}
(0, _createClass3.default)(DynamicComponent, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.mounted = true;
}
}, {
key: 'load',
value: function load() {
var _this2 = this;
resolve().then(function (m) {
var AsyncComponent = m.default || m;
if (_this2.mounted) {
_this2.setState({ AsyncComponent: AsyncComponent });
} else {
_this2.state.AsyncComponent = AsyncComponent; // eslint-disable-line
}
});
}
}, {
key: 'render',
value: function render() {
var AsyncComponent = this.state.AsyncComponent;
var LoadingComponent = this.LoadingComponent;
if (AsyncComponent) return _react2.default.createElement(AsyncComponent, this.props);
return _react2.default.createElement(LoadingComponent, this.props);
}
}]);
return DynamicComponent;
}(_react.Component);
}
function dynamic(config) {

@@ -40,3 +124,3 @@ var app = config.app,

return (0, _reactAsyncComponent.asyncComponent)((0, _extends3.default)({
return asyncComponent((0, _extends3.default)({
resolve: config.resolve || function () {

@@ -43,0 +127,0 @@ var models = typeof resolveModels === 'function' ? resolveModels() : [];

2

package.json
{
"name": "dva",
"version": "2.0.4",
"version": "2.1.0-beta.1",
"description": "React and redux based, lightweight and elm-style framework.",

@@ -5,0 +5,0 @@ "repository": {

@@ -1,2 +0,2 @@

import { asyncComponent } from 'react-async-component';
import React, { Component } from 'react';

@@ -11,2 +11,41 @@ const cached = {};

function asyncComponent(config) {
const { resolve } = config;
return class DynamicComponent extends Component {
constructor(...args) {
super(...args);
this.LoadingComponent =
config.LoadingComponent || (() => null);
this.state = {
AsyncComponent: null,
};
this.load();
}
componentDidMount() {
this.mounted = true;
}
load() {
resolve().then((m) => {
const AsyncComponent = m.default || m;
if (this.mounted) {
this.setState({ AsyncComponent });
} else {
this.state.AsyncComponent = AsyncComponent; // eslint-disable-line
}
});
}
render() {
const { AsyncComponent } = this.state;
const { LoadingComponent } = this;
if (AsyncComponent) return <AsyncComponent {...this.props} />;
return <LoadingComponent {...this.props} />;
}
};
}
export default function dynamic(config) {

@@ -13,0 +52,0 @@ const { app, models: resolveModels, component: resolveComponent } = config;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc