@goldfishjs/route
Advanced tools
Comparing version 2.21.1 to 2.22.0-alpha.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [2.22.0-alpha.0](https://github.com/alipay/goldfish/compare/v2.21.1...v2.22.0-alpha.0) (2022-11-08) | ||
**Note:** Version bump only for package @goldfishjs/route | ||
## [2.21.1](https://github.com/alipay/goldfish/compare/v2.21.1-alpha.0...v2.21.1) (2022-10-03) | ||
@@ -8,0 +16,0 @@ |
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
var BaseRouter = /*#__PURE__*/function () { | ||
function BaseRouter() { | ||
_classCallCheck(this, BaseRouter); | ||
_defineProperty(this, "fromuKey", 'fromu'); | ||
_defineProperty(this, "path", ''); | ||
_defineProperty(this, "query", {}); | ||
_defineProperty(this, "changeListeners", []); | ||
} | ||
_createClass(BaseRouter, [{ | ||
@@ -22,3 +16,2 @@ key: "addChangeListener", | ||
var _this = this; | ||
this.changeListeners.push(listener); | ||
@@ -40,3 +33,2 @@ return function () { | ||
*/ | ||
}, { | ||
@@ -46,3 +38,2 @@ key: "change", | ||
var isChanged = false; | ||
if (path !== this.path) { | ||
@@ -52,3 +43,2 @@ this.setPath(path, true); | ||
} | ||
if (!this.isQueryEqual(query, this.query)) { | ||
@@ -58,3 +48,2 @@ this.setQuery(query, true); | ||
} | ||
isChanged && this.invokeChangeListeners(); | ||
@@ -76,3 +65,2 @@ } | ||
var silent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
if (this.path !== path) { | ||
@@ -91,3 +79,2 @@ this.path = path; | ||
} | ||
for (var _key in q2) { | ||
@@ -98,3 +85,2 @@ if (q1[_key] !== q2[_key]) { | ||
} | ||
return true; | ||
@@ -106,3 +92,2 @@ } | ||
var silent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
if (!this.isQueryEqual(query, this.query)) { | ||
@@ -117,3 +102,2 @@ this.query = query; | ||
var _this2 = this; | ||
var listeners = this.changeListeners; | ||
@@ -125,6 +109,4 @@ listeners.forEach(function (listener) { | ||
}]); | ||
return BaseRouter; | ||
}(); | ||
export { BaseRouter as default }; |
@@ -9,11 +9,6 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
import { parse, stringify } from 'qs'; | ||
@@ -33,10 +28,7 @@ import BaseRouter from './BaseRouter'; | ||
*/ | ||
export function format(url, params) { | ||
var _parseUrl = parseUrl(url), | ||
path = _parseUrl.path, | ||
query = _parseUrl.query; | ||
path = _parseUrl.path, | ||
query = _parseUrl.query; | ||
var realQuery = _objectSpread(_objectSpread({}, query), params || {}); | ||
var queryStr = stringify(realQuery); | ||
@@ -46,24 +38,15 @@ var realQueryStr = queryStr ? "?".concat(queryStr) : ''; | ||
} | ||
var StackedRouter = /*#__PURE__*/function (_BaseRouter) { | ||
_inherits(StackedRouter, _BaseRouter); | ||
var _super = _createSuper(StackedRouter); | ||
function StackedRouter() { | ||
var _this; | ||
_classCallCheck(this, StackedRouter); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "fromuKey", 'fromu'); | ||
return _this; | ||
} | ||
_createClass(StackedRouter, [{ | ||
@@ -80,5 +63,4 @@ key: "redirect", | ||
var _parseUrl2 = parseUrl(url), | ||
path = _parseUrl2.path, | ||
query = _parseUrl2.query; | ||
path = _parseUrl2.path, | ||
query = _parseUrl2.query; | ||
this.change(path, _objectSpread(_objectSpread(_objectSpread({}, query), params), {}, _defineProperty({}, this.fromuKey, format(this.getPath(), this.getQuery())))); | ||
@@ -91,3 +73,2 @@ } | ||
*/ | ||
}, { | ||
@@ -98,19 +79,14 @@ key: "back", | ||
var defaultUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/'; | ||
if (n < 0) { | ||
throw new Error('The back steps must be a positive integer.'); | ||
} | ||
if (n === 0) { | ||
return; | ||
} | ||
var normalizedN = n - 1; | ||
var stack = this.parseFromuStack(this.getQuery()); | ||
var targetUrl = stack[normalizedN]; | ||
var _parseUrl3 = parseUrl(targetUrl || defaultUrl), | ||
path = _parseUrl3.path, | ||
query = _parseUrl3.query; | ||
path = _parseUrl3.path, | ||
query = _parseUrl3.query; | ||
this.change(path, query); | ||
@@ -127,3 +103,2 @@ } | ||
*/ | ||
}, { | ||
@@ -133,20 +108,15 @@ key: "backTo", | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$removeStackLengt = _ref.removeStackLength, | ||
removeStackLength = _ref$removeStackLengt === void 0 ? 1 : _ref$removeStackLengt, | ||
_ref$params = _ref.params, | ||
params = _ref$params === void 0 ? {} : _ref$params; | ||
_ref$removeStackLengt = _ref.removeStackLength, | ||
removeStackLength = _ref$removeStackLengt === void 0 ? 1 : _ref$removeStackLengt, | ||
_ref$params = _ref.params, | ||
params = _ref$params === void 0 ? {} : _ref$params; | ||
var normalizedRemovedStackLength = removeStackLength - 1; | ||
var stack = this.parseFromuStack(this.getQuery()); | ||
var _parseUrl4 = parseUrl(url), | ||
path = _parseUrl4.path, | ||
query = _parseUrl4.query; | ||
path = _parseUrl4.path, | ||
query = _parseUrl4.query; | ||
var realQuery = _objectSpread(_objectSpread({}, query), params); | ||
if (stack.length > normalizedRemovedStackLength) { | ||
realQuery[this.fromuKey] = stack[normalizedRemovedStackLength]; | ||
} | ||
this.change(path, realQuery); | ||
@@ -176,3 +146,2 @@ } | ||
*/ | ||
}, { | ||
@@ -182,21 +151,15 @@ key: "parseFromuStack", | ||
var stack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (query[this.fromuKey]) { | ||
var fromu = query[this.fromuKey]; | ||
if (Array.isArray(fromu)) { | ||
throw new Error("do not use multiple fromu: ".concat(JSON.stringify(query))); | ||
} | ||
stack.push(fromu); | ||
return this.parseFromuStack(parse(fromu.split('?')[1]), stack); | ||
} | ||
return stack; | ||
} | ||
}]); | ||
return StackedRouter; | ||
}(BaseRouter); | ||
export { StackedRouter as default }; |
@@ -9,23 +9,13 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
import StackedRouter, { format } from './StackedRouter'; | ||
var TinyAppRouter = /*#__PURE__*/function (_StackedRouter) { | ||
_inherits(TinyAppRouter, _StackedRouter); | ||
var _super = _createSuper(TinyAppRouter); | ||
function TinyAppRouter() { | ||
var _this; | ||
_classCallCheck(this, TinyAppRouter); | ||
_this = _super.call(this); | ||
_defineProperty(_assertThisInitialized(_this), "removeChangeListener", void 0); | ||
_this.removeChangeListener = _this.addChangeListener(function () { | ||
@@ -39,3 +29,2 @@ var realUrl = format(_this.getPath(), _this.getQuery()); | ||
} | ||
_createClass(TinyAppRouter, [{ | ||
@@ -45,3 +34,2 @@ key: "destroy", | ||
_get(_getPrototypeOf(TinyAppRouter.prototype), "destroy", this).call(this); | ||
this.removeChangeListener(); | ||
@@ -71,6 +59,4 @@ } | ||
}]); | ||
return TinyAppRouter; | ||
}(StackedRouter); | ||
export { TinyAppRouter as default }; |
@@ -8,34 +8,21 @@ import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
import Route from './Route'; | ||
import { default as BaseTinyappRoute } from './container-router/TinyAppRouter'; | ||
var TinyappRoute = /*#__PURE__*/function (_Route) { | ||
_inherits(TinyappRoute, _Route); | ||
var _super = _createSuper(TinyappRoute); | ||
function TinyappRoute() { | ||
var _this; | ||
_classCallCheck(this, TinyappRoute); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "route", new BaseTinyappRoute()); | ||
return _this; | ||
} | ||
return _createClass(TinyappRoute); | ||
}(Route); | ||
export default new TinyappRoute(); |
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
var Route = /*#__PURE__*/function () { | ||
function Route() { | ||
_classCallCheck(this, Route); | ||
_defineProperty(this, "path", null); | ||
_defineProperty(this, "query", {}); | ||
_defineProperty(this, "removeChangeListener", void 0); | ||
} | ||
_createClass(Route, [{ | ||
@@ -20,3 +15,2 @@ key: "start", | ||
var _this = this; | ||
this.removeChangeListener = this.route.addChangeListener(function (path, query) { | ||
@@ -33,3 +27,2 @@ _this.path = path; | ||
} | ||
this.route.destroy(); | ||
@@ -74,6 +67,4 @@ } | ||
}]); | ||
return Route; | ||
}(); | ||
export { Route as default }; |
{ | ||
"name": "@goldfishjs/route", | ||
"version": "2.21.1", | ||
"version": "2.22.0-alpha.0", | ||
"description": "goldfish-route", | ||
@@ -17,3 +17,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@goldfishjs/module-usage": "^2.21.1", | ||
"@goldfishjs/module-usage": "^2.22.0-alpha.0", | ||
"@types/qs": "^6.9.0", | ||
@@ -20,0 +20,0 @@ "mini-types": "^0.1.7", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32847
2