Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uiw/react-amap-api-loader

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uiw/react-amap-api-loader - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

266

cjs/index.js

@@ -5,3 +5,5 @@ "use strict";

exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.delay = delay;

@@ -12,6 +14,18 @@ exports.APILoader = void 0;

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");

@@ -36,4 +50,6 @@

var APILoader = /*#__PURE__*/function (_Component) {
(0, _inheritsLoose2["default"])(APILoader, _Component);
(0, _inherits2["default"])(APILoader, _Component);
var _super = (0, _createSuper2["default"])(APILoader);
/**

@@ -45,18 +61,17 @@ * 全局可能存在多个 Loader 同时渲染, 但是只能由一个负责加载

_this = _Component.call(this, props) || this;
_this.state = {
(0, _classCallCheck2["default"])(this, APILoader);
_this = _super.call(this, props);
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
loaded: !!window.AMap
};
_this.handleError = function (error) {
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleError", function (error) {
_this.setState({
error: error
});
};
_this.finish = function () {
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "finish", function () {
_this.setState({
loaded: true
});
};
});

@@ -70,144 +85,145 @@ if (props.akay === null) {

var _proto = APILoader.prototype;
(0, _createClass2["default"])(APILoader, [{
key: "componentDidMount",
value: function componentDidMount() {
var callbackName = this.props.callbackName;
_proto.componentDidMount = function componentDidMount() {
var callbackName = this.props.callbackName;
if (window.AMap == null) {
if (window[callbackName]) {
APILoader.waitQueue.push([this.finish, this.handleError]);
return;
}
if (window.AMap == null) {
if (window[callbackName]) {
APILoader.waitQueue.push([this.finish, this.handleError]);
return;
this.loadMap();
}
this.loadMap();
}
};
}, {
key: "render",
value: function render() {
return this.state.loaded ? this.props.children : this.props.fallback ? this.props.fallback(this.state.error) : this.state.error ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
style: {
color: 'red'
},
children: this.state.error.message
}) : null;
}
}, {
key: "getScriptSrc",
value: function getScriptSrc() {
var cfg = this.props;
var protocol = cfg.protocol || window.location.protocol;
_proto.render = function render() {
return this.state.loaded ? this.props.children : this.props.fallback ? this.props.fallback(this.state.error) : this.state.error ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
style: {
color: 'red'
},
children: this.state.error.message
}) : null;
};
if (protocol.indexOf(':') === -1) {
protocol += ':';
}
_proto.getScriptSrc = function getScriptSrc() {
var cfg = this.props;
var protocol = cfg.protocol || window.location.protocol;
var plugin = '';
if (protocol.indexOf(':') === -1) {
protocol += ':';
if (cfg.plugin) {
plugin = "&plugin=".concat(cfg.plugin);
}
return "".concat(protocol, "//").concat(cfg.hostAndPath, "?v=").concat(cfg.version, "&key=").concat(cfg.akay, "&callback=").concat(cfg.callbackName).concat(plugin);
}
/**
* load BaiduMap in script tag
*/
var plugin = '';
}, {
key: "loadMap",
value: function () {
var _loadMap = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _this2 = this;
if (cfg.plugin) {
plugin = "&plugin=" + cfg.plugin;
}
var callbackName, src, i, _ret;
return protocol + "//" + cfg.hostAndPath + "?v=" + cfg.version + "&key=" + cfg.akay + "&callback=" + cfg.callbackName + plugin;
}
/**
* load BaiduMap in script tag
*/
;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
callbackName = this.props.callbackName;
src = this.getScriptSrc();
_proto.loadMap =
/*#__PURE__*/
function () {
var _loadMap = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _this2 = this;
window[callbackName] = function () {
// flush queue
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[0]();
});
var callbackName, src, i, _ret;
_this2.finish();
};
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
callbackName = this.props.callbackName;
src = this.getScriptSrc();
i = 0;
window[callbackName] = function () {
// flush queue
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[0]();
});
case 4:
if (!(i < DEFAULT_RETRY_TIME)) {
_context.next = 22;
break;
}
_this2.finish();
};
_context.prev = 5;
_context.next = 8;
return (0, _reactAmapRequireScript.requireScript)(src);
i = 0;
case 8:
return _context.abrupt("break", 22);
case 4:
if (!(i < DEFAULT_RETRY_TIME)) {
_context.next = 22;
break;
}
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](5);
_context.prev = 5;
_context.next = 8;
return (0, _reactAmapRequireScript.requireScript)(src);
if (!(i === DEFAULT_RETRY_TIME - 1)) {
_context.next = 17;
break;
}
case 8:
return _context.abrupt("break", 22);
_ret = function () {
var err = new Error("Failed to load AMap: ".concat(_context.t0.message)); // flush queue
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](5);
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[1](err);
});
if (!(i === DEFAULT_RETRY_TIME - 1)) {
_context.next = 17;
break;
}
_this2.handleError(err);
_ret = function () {
var err = new Error("Failed to load AMap: " + _context.t0.message); // flush queue
return {
v: void 0
};
}();
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[1](err);
});
if (!((0, _typeof2["default"])(_ret) === "object")) {
_context.next = 17;
break;
}
_this2.handleError(err);
return _context.abrupt("return", _ret.v);
return {
v: void 0
};
}();
case 17:
_context.next = 19;
return delay(i * 1000);
if (!(typeof _ret === "object")) {
_context.next = 17;
case 19:
i++;
_context.next = 4;
break;
}
return _context.abrupt("return", _ret.v);
case 17:
_context.next = 19;
return delay(i * 1000);
case 19:
i++;
_context.next = 4;
break;
case 22:
case "end":
return _context.stop();
case 22:
case "end":
return _context.stop();
}
}
}
}, _callee, this, [[5, 11]]);
}));
}, _callee, this, [[5, 11]]);
}));
function loadMap() {
return _loadMap.apply(this, arguments);
}
function loadMap() {
return _loadMap.apply(this, arguments);
}
return loadMap;
}();
return loadMap;
}()
}]);
return APILoader;

@@ -217,3 +233,3 @@ }(_react.Component);

exports.APILoader = APILoader;
APILoader.defaultProps = {
(0, _defineProperty2["default"])(APILoader, "defaultProps", {
akay: '',

@@ -224,4 +240,4 @@ hostAndPath: 'webapi.amap.com/maps',

plugin: ''
};
APILoader.waitQueue = [];
});
(0, _defineProperty2["default"])(APILoader, "waitQueue", []);
//# sourceMappingURL=index.js.map

@@ -1,13 +0,26 @@

import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import _regeneratorRuntime from "@babel/runtime/regenerator";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.delay = delay;
exports.APILoader = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _react = require("react");
var _reactAmapRequireScript = require("@uiw/react-amap-require-script");
var _jsxRuntime = require("react/jsx-runtime");
/// <reference types="@uiw/react-amap-types" />
import { Component } from 'react';
import { requireScript } from '@uiw/react-amap-require-script';
import { jsx as _jsx } from "react/jsx-runtime";
export function delay(time) {
return new Promise(function (resolve, reject) {
function delay(time) {
return new Promise((resolve, reject) => {
window.setTimeout(resolve, time);
});
}
var DEFAULT_RETRY_TIME = 3;

@@ -18,24 +31,20 @@ /**

export var APILoader = /*#__PURE__*/function (_Component) {
_inheritsLoose(APILoader, _Component);
class APILoader extends _react.Component {
/**
* 全局可能存在多个 Loader 同时渲染, 但是只能由一个负责加载
*/
function APILoader(props) {
var _this;
_this = _Component.call(this, props) || this;
_this.state = {
constructor(props) {
super(props);
this.state = {
loaded: !!window.AMap
};
_this.handleError = function (error) {
_this.setState({
error: error
this.handleError = error => {
this.setState({
error
});
};
_this.finish = function () {
_this.setState({
this.finish = () => {
this.setState({
loaded: true

@@ -48,11 +57,9 @@ });

}
return _this;
}
var _proto = APILoader.prototype;
componentDidMount() {
var {
callbackName
} = this.props;
_proto.componentDidMount = function componentDidMount() {
var callbackName = this.props.callbackName;
if (window.AMap == null) {

@@ -66,6 +73,6 @@ if (window[callbackName]) {

}
};
}
_proto.render = function render() {
return this.state.loaded ? this.props.children : this.props.fallback ? this.props.fallback(this.state.error) : this.state.error ? /*#__PURE__*/_jsx("div", {
render() {
return this.state.loaded ? this.props.children : this.props.fallback ? this.props.fallback(this.state.error) : this.state.error ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
style: {

@@ -76,5 +83,5 @@ color: 'red'

}) : null;
};
}
_proto.getScriptSrc = function getScriptSrc() {
getScriptSrc() {
var cfg = this.props;

@@ -98,103 +105,55 @@ var protocol = cfg.protocol || window.location.protocol;

*/
;
_proto.loadMap =
/*#__PURE__*/
function () {
var _loadMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _this2 = this;
var callbackName, src, i, _ret;
loadMap() {
var _this = this;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
callbackName = this.props.callbackName;
src = this.getScriptSrc();
return (0, _asyncToGenerator2.default)(function* () {
var {
callbackName
} = _this.props;
window[callbackName] = function () {
// flush queue
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[0]();
});
var src = _this.getScriptSrc();
_this2.finish();
};
window[callbackName] = () => {
// flush queue
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(task => task[0]());
i = 0;
_this.finish();
};
case 4:
if (!(i < DEFAULT_RETRY_TIME)) {
_context.next = 22;
break;
}
for (var i = 0; i < DEFAULT_RETRY_TIME; i++) {
try {
yield (0, _reactAmapRequireScript.requireScript)(src);
break;
} catch (error) {
if (i === DEFAULT_RETRY_TIME - 1) {
var _ret = function () {
var err = new Error("Failed to load AMap: " + error.message); // flush queue
_context.prev = 5;
_context.next = 8;
return requireScript(src);
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(task => task[1](err));
case 8:
return _context.abrupt("break", 22);
_this.handleError(err);
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](5);
return {
v: void 0
};
}();
if (!(i === DEFAULT_RETRY_TIME - 1)) {
_context.next = 17;
break;
}
if (typeof _ret === "object") return _ret.v;
}
_ret = function () {
var err = new Error("Failed to load AMap: " + _context.t0.message); // flush queue
var queue = APILoader.waitQueue;
APILoader.waitQueue = [];
queue.forEach(function (task) {
return task[1](err);
});
_this2.handleError(err);
return {
v: void 0
};
}();
if (!(typeof _ret === "object")) {
_context.next = 17;
break;
}
return _context.abrupt("return", _ret.v);
case 17:
_context.next = 19;
return delay(i * 1000);
case 19:
i++;
_context.next = 4;
break;
case 22:
case "end":
return _context.stop();
}
yield delay(i * 1000);
}
}, _callee, this, [[5, 11]]);
}));
}
})();
}
function loadMap() {
return _loadMap.apply(this, arguments);
}
}
return loadMap;
}();
return APILoader;
}(Component);
exports.APILoader = APILoader;
APILoader.defaultProps = {

@@ -201,0 +160,0 @@ akay: '',

{
"name": "@uiw/react-amap-api-loader",
"version": "2.2.1",
"version": "2.2.2",
"description": "用于加载高德地图 SDK 依赖,加载完成,全局将会有 **`window.AMap`** 对象。",

@@ -36,5 +36,5 @@ "homepage": "https://uiwjs.github.io/react-amap/#/api-loader",

"dependencies": {
"@uiw/react-amap-require-script": "^2.2.1",
"@uiw/react-amap-types": "^2.2.1"
"@uiw/react-amap-require-script": "^2.2.2",
"@uiw/react-amap-types": "^2.2.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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