routup 3.0.0-alpha.1 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1791,14 +1791,17 @@ function isLayerInstance(input) {
1791
1791
  return isInstance(input, LayerSymbol);
1792
1792
  }
1793
1793
 
1794
- function isPluginInstallContext(input) {
1795
- if (!isObject(input) || !isObject(input.options)) {
1794
+ function isPlugin(input) {
1795
+ if (!isObject(input)) {
1796
1796
  return false;
1797
1797
  }
1798
1798
  if (typeof input.name !== 'undefined' && typeof input.name !== 'string') {
1799
1799
  return false;
1800
1800
  }
1801
- return typeof input.path === 'undefined' || isPath(input.path);
1801
+ if (typeof input.install !== 'function' || input.install.length !== 1) {
1802
+ return false;
1803
+ }
1804
+ return typeof input.version === 'undefined' || typeof input.version === 'string';
1802
1805
  }
1803
1806
 
1804
1807
  function transformRouterOptions(input) {
@@ -2026,9 +2029,6 @@ class Router {
2026
2029
  return this;
2027
2030
  }
2028
2031
  use(...input) {
2029
- /* istanbul ignore next */ if (input.length === 0) {
2030
- return this;
2031
- }
2032
2032
  const modifyPath = (input)=>{
2033
2033
  if (typeof input === 'string') {
2034
2034
  return withLeadingSlash(input);
@@ -2053,33 +2053,32 @@ class Router {
2053
2053
  item.path = path || modifyPath(item.path);
2054
2054
  this.stack.push(new Layer(item));
2055
2055
  }
2056
+ if (isPlugin(item)) {
2057
+ if (path) {
2058
+ this.install(item, {
2059
+ path
2060
+ });
2061
+ } else {
2062
+ this.install(item);
2063
+ }
2064
+ }
2056
2065
  }
2057
2066
  return this;
2058
2067
  }
2059
2068
  // --------------------------------------------------
2060
- install(plugin, context) {
2061
- if (isPluginInstallContext(context)) {
2062
- const name = context.name || plugin.name;
2063
- if (context.path) {
2064
- const router = new Router({
2065
- name
2066
- });
2067
- plugin.install(router, context.options);
2068
- this.use(context.path, router);
2069
- return this;
2070
- }
2071
- plugin.install(this, context.options);
2069
+ install(plugin, context = {}) {
2070
+ const name = context.name || plugin.name;
2071
+ if (context.path) {
2072
+ const router = new Router({
2073
+ name
2074
+ });
2075
+ plugin.install(router);
2076
+ this.use(context.path, router);
2072
2077
  return this;
2073
2078
  }
2074
- plugin.install(this, context);
2079
+ plugin.install(this);
2075
2080
  return this;
2076
2081
  }
2077
- uninstall(name) {
2078
- const index = this.stack.findIndex((el)=>isRouterInstance(el) && el.name === name);
2079
- if (index !== -1) {
2080
- this.stack.splice(index, 1);
2081
- }
2082
- }
2083
2082
  // --------------------------------------------------
2084
2083
  constructor(options = {}){
2085
2084
  this['@instanceof'] = RouterSymbol;
@@ -2137,7 +2136,7 @@ exports.isError = isError;
2137
2136
  exports.isHandler = isHandler;
2138
2137
  exports.isLayerInstance = isLayerInstance;
2139
2138
  exports.isPath = isPath;
2140
- exports.isPluginInstallContext = isPluginInstallContext;
2139
+ exports.isPlugin = isPlugin;
2141
2140
  exports.isRequestCacheable = isRequestCacheable;
2142
2141
  exports.isResponseGone = isResponseGone;
2143
2142
  exports.isRouterInstance = isRouterInstance;