@umijs/runtime
Advanced tools
Comparing version 3.5.0-beta.4 to 3.5.0-beta.5
@@ -1,7 +0,7 @@ | ||
export { Link, NavLink, Prompt, Redirect, Route, Router, StaticRouter, MemoryRouter, Switch, matchPath, withRouter, useHistory, useLocation, useParams, useRouteMatch, } from 'react-router-dom'; | ||
export { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history-with-query'; | ||
export type { History, MemoryHistory } from 'history-with-query'; | ||
export { __RouterContext } from 'react-router'; | ||
export { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history-with-query'; | ||
export type { MemoryHistory, History } from 'history-with-query'; | ||
export { default as Plugin, ApplyPluginsType } from './Plugin/Plugin'; | ||
export { Link, matchPath, MemoryRouter, NavLink, Prompt, Redirect, Route, Router, StaticRouter, Switch, useHistory, useLocation, useParams, useRouteMatch, withRouter, } from 'react-router-dom'; | ||
export { default as dynamic } from './dynamic/dynamic'; | ||
export { ApplyPluginsType, default as Plugin } from './Plugin/Plugin'; | ||
export { isBrowser } from './utils/index'; |
@@ -0,4 +1,4 @@ | ||
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history-with-query'; | ||
export { __RouterContext } from 'react-router'; | ||
export { Link, MemoryRouter, NavLink, Prompt, Redirect, Route, Router, StaticRouter, Switch, matchPath, useHistory, useLocation, useParams, useRouteMatch, withRouter } from 'react-router-dom'; | ||
export { __RouterContext } from 'react-router'; | ||
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history-with-query'; | ||
import { createContext, forwardRef, createElement, useContext, useImperativeHandle } from 'react'; | ||
@@ -224,224 +224,2 @@ import { useSubscription } from 'use-subscription'; | ||
function assert(value, message) { | ||
if (!value) throw new Error(message); | ||
} | ||
/** | ||
* whether in browser env | ||
*/ | ||
var isBrowser = function isBrowser() { | ||
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
}; | ||
var ApplyPluginsType; | ||
(function (ApplyPluginsType) { | ||
ApplyPluginsType["compose"] = "compose"; | ||
ApplyPluginsType["modify"] = "modify"; | ||
ApplyPluginsType["event"] = "event"; | ||
})(ApplyPluginsType || (ApplyPluginsType = {})); | ||
function _compose(_ref) { | ||
var fns = _ref.fns, | ||
args = _ref.args; | ||
if (fns.length === 1) { | ||
return fns[0]; | ||
} | ||
var last = fns.pop(); | ||
return fns.reduce(function (a, b) { | ||
return function () { | ||
return b(a, args); | ||
}; | ||
}, last); | ||
} | ||
function isPromiseLike(obj) { | ||
return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function'; | ||
} | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(opts) { | ||
_classCallCheck(this, Plugin); | ||
this.hooks = {}; | ||
this.validKeys = (opts === null || opts === void 0 ? void 0 : opts.validKeys) || []; | ||
} | ||
_createClass(Plugin, [{ | ||
key: "register", | ||
value: function register(plugin) { | ||
var _this = this; | ||
assert(!!plugin.apply, "register failed, plugin.apply must supplied"); | ||
assert(!!plugin.path, "register failed, plugin.path must supplied"); | ||
Object.keys(plugin.apply).forEach(function (key) { | ||
assert(_this.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " from plugin ").concat(plugin.path, ".")); | ||
if (!_this.hooks[key]) _this.hooks[key] = []; | ||
_this.hooks[key] = _this.hooks[key].concat(plugin.apply[key]); | ||
}); | ||
} | ||
}, { | ||
key: "getHooks", | ||
value: function getHooks(keyWithDot) { | ||
var _keyWithDot$split = keyWithDot.split('.'), | ||
_keyWithDot$split2 = _toArray(_keyWithDot$split), | ||
key = _keyWithDot$split2[0], | ||
memberKeys = _keyWithDot$split2.slice(1); | ||
var hooks = this.hooks[key] || []; | ||
if (memberKeys.length) { | ||
hooks = hooks.map(function (hook) { | ||
try { | ||
var ret = hook; | ||
var _iterator = _createForOfIteratorHelper(memberKeys), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var memberKey = _step.value; | ||
ret = ret[memberKey]; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return ret; | ||
} catch (e) { | ||
return null; | ||
} | ||
}).filter(Boolean); | ||
} | ||
return hooks; | ||
} | ||
}, { | ||
key: "applyPlugins", | ||
value: function applyPlugins(_ref2) { | ||
var key = _ref2.key, | ||
type = _ref2.type, | ||
initialValue = _ref2.initialValue, | ||
args = _ref2.args, | ||
async = _ref2.async; | ||
var hooks = this.getHooks(key) || []; | ||
if (args) { | ||
assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object."); | ||
} | ||
switch (type) { | ||
case ApplyPluginsType.modify: | ||
if (async) { | ||
return hooks.reduce( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(memo, hook) { | ||
var ret; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise.")); | ||
if (!isPromiseLike(memo)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.next = 4; | ||
return memo; | ||
case 4: | ||
memo = _context.sent; | ||
case 5: | ||
if (!(typeof hook === 'function')) { | ||
_context.next = 16; | ||
break; | ||
} | ||
ret = hook(memo, args); | ||
if (!isPromiseLike(ret)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
_context.next = 10; | ||
return ret; | ||
case 10: | ||
return _context.abrupt("return", _context.sent); | ||
case 13: | ||
return _context.abrupt("return", ret); | ||
case 14: | ||
_context.next = 21; | ||
break; | ||
case 16: | ||
if (!isPromiseLike(hook)) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.next = 19; | ||
return hook; | ||
case 19: | ||
hook = _context.sent; | ||
case 20: | ||
return _context.abrupt("return", _objectSpread2(_objectSpread2({}, memo), hook)); | ||
case 21: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue)); | ||
} else { | ||
return hooks.reduce(function (memo, hook) { | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object.")); | ||
if (typeof hook === 'function') { | ||
return hook(memo, args); | ||
} else { | ||
// TODO: deepmerge? | ||
return _objectSpread2(_objectSpread2({}, memo), hook); | ||
} | ||
}, initialValue); | ||
} | ||
case ApplyPluginsType.event: | ||
return hooks.forEach(function (hook) { | ||
assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function.")); | ||
hook(args); | ||
}); | ||
case ApplyPluginsType.compose: | ||
return function () { | ||
return _compose({ | ||
fns: hooks.concat(initialValue), | ||
args: args | ||
})(); | ||
}; | ||
} | ||
} | ||
}]); | ||
return Plugin; | ||
}(); | ||
var LoadableContext = /*#__PURE__*/createContext(null); | ||
@@ -816,2 +594,224 @@ | ||
function assert(value, message) { | ||
if (!value) throw new Error(message); | ||
} | ||
/** | ||
* whether in browser env | ||
*/ | ||
var isBrowser = function isBrowser() { | ||
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
}; | ||
var ApplyPluginsType; | ||
(function (ApplyPluginsType) { | ||
ApplyPluginsType["compose"] = "compose"; | ||
ApplyPluginsType["modify"] = "modify"; | ||
ApplyPluginsType["event"] = "event"; | ||
})(ApplyPluginsType || (ApplyPluginsType = {})); | ||
function _compose(_ref) { | ||
var fns = _ref.fns, | ||
args = _ref.args; | ||
if (fns.length === 1) { | ||
return fns[0]; | ||
} | ||
var last = fns.pop(); | ||
return fns.reduce(function (a, b) { | ||
return function () { | ||
return b(a, args); | ||
}; | ||
}, last); | ||
} | ||
function isPromiseLike(obj) { | ||
return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function'; | ||
} | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(opts) { | ||
_classCallCheck(this, Plugin); | ||
this.hooks = {}; | ||
this.validKeys = (opts === null || opts === void 0 ? void 0 : opts.validKeys) || []; | ||
} | ||
_createClass(Plugin, [{ | ||
key: "register", | ||
value: function register(plugin) { | ||
var _this = this; | ||
assert(!!plugin.apply, "register failed, plugin.apply must supplied"); | ||
assert(!!plugin.path, "register failed, plugin.path must supplied"); | ||
Object.keys(plugin.apply).forEach(function (key) { | ||
assert(_this.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " from plugin ").concat(plugin.path, ".")); | ||
if (!_this.hooks[key]) _this.hooks[key] = []; | ||
_this.hooks[key] = _this.hooks[key].concat(plugin.apply[key]); | ||
}); | ||
} | ||
}, { | ||
key: "getHooks", | ||
value: function getHooks(keyWithDot) { | ||
var _keyWithDot$split = keyWithDot.split('.'), | ||
_keyWithDot$split2 = _toArray(_keyWithDot$split), | ||
key = _keyWithDot$split2[0], | ||
memberKeys = _keyWithDot$split2.slice(1); | ||
var hooks = this.hooks[key] || []; | ||
if (memberKeys.length) { | ||
hooks = hooks.map(function (hook) { | ||
try { | ||
var ret = hook; | ||
var _iterator = _createForOfIteratorHelper(memberKeys), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var memberKey = _step.value; | ||
ret = ret[memberKey]; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return ret; | ||
} catch (e) { | ||
return null; | ||
} | ||
}).filter(Boolean); | ||
} | ||
return hooks; | ||
} | ||
}, { | ||
key: "applyPlugins", | ||
value: function applyPlugins(_ref2) { | ||
var key = _ref2.key, | ||
type = _ref2.type, | ||
initialValue = _ref2.initialValue, | ||
args = _ref2.args, | ||
async = _ref2.async; | ||
var hooks = this.getHooks(key) || []; | ||
if (args) { | ||
assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object."); | ||
} | ||
switch (type) { | ||
case ApplyPluginsType.modify: | ||
if (async) { | ||
return hooks.reduce( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(memo, hook) { | ||
var ret; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise.")); | ||
if (!isPromiseLike(memo)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.next = 4; | ||
return memo; | ||
case 4: | ||
memo = _context.sent; | ||
case 5: | ||
if (!(typeof hook === 'function')) { | ||
_context.next = 16; | ||
break; | ||
} | ||
ret = hook(memo, args); | ||
if (!isPromiseLike(ret)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
_context.next = 10; | ||
return ret; | ||
case 10: | ||
return _context.abrupt("return", _context.sent); | ||
case 13: | ||
return _context.abrupt("return", ret); | ||
case 14: | ||
_context.next = 21; | ||
break; | ||
case 16: | ||
if (!isPromiseLike(hook)) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.next = 19; | ||
return hook; | ||
case 19: | ||
hook = _context.sent; | ||
case 20: | ||
return _context.abrupt("return", _objectSpread2(_objectSpread2({}, memo), hook)); | ||
case 21: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue)); | ||
} else { | ||
return hooks.reduce(function (memo, hook) { | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object.")); | ||
if (typeof hook === 'function') { | ||
return hook(memo, args); | ||
} else { | ||
// TODO: deepmerge? | ||
return _objectSpread2(_objectSpread2({}, memo), hook); | ||
} | ||
}, initialValue); | ||
} | ||
case ApplyPluginsType.event: | ||
return hooks.forEach(function (hook) { | ||
assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function.")); | ||
hook(args); | ||
}); | ||
case ApplyPluginsType.compose: | ||
return function () { | ||
return _compose({ | ||
fns: hooks.concat(initialValue), | ||
args: args | ||
})(); | ||
}; | ||
} | ||
} | ||
}]); | ||
return Plugin; | ||
}(); | ||
export { ApplyPluginsType, Plugin, dynamic, isBrowser }; |
@@ -5,5 +5,5 @@ 'use strict'; | ||
var historyWithQuery = require('history-with-query'); | ||
var reactRouter = require('react-router'); | ||
var reactRouterDom = require('react-router-dom'); | ||
var reactRouter = require('react-router'); | ||
var historyWithQuery = require('history-with-query'); | ||
var React = require('react'); | ||
@@ -229,222 +229,2 @@ var useSubscription = require('use-subscription'); | ||
function assert(value, message) { | ||
if (!value) throw new Error(message); | ||
} | ||
/** | ||
* whether in browser env | ||
*/ | ||
var isBrowser = function isBrowser() { | ||
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
}; | ||
(function (ApplyPluginsType) { | ||
ApplyPluginsType["compose"] = "compose"; | ||
ApplyPluginsType["modify"] = "modify"; | ||
ApplyPluginsType["event"] = "event"; | ||
})(exports.ApplyPluginsType || (exports.ApplyPluginsType = {})); | ||
function _compose(_ref) { | ||
var fns = _ref.fns, | ||
args = _ref.args; | ||
if (fns.length === 1) { | ||
return fns[0]; | ||
} | ||
var last = fns.pop(); | ||
return fns.reduce(function (a, b) { | ||
return function () { | ||
return b(a, args); | ||
}; | ||
}, last); | ||
} | ||
function isPromiseLike(obj) { | ||
return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function'; | ||
} | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(opts) { | ||
_classCallCheck(this, Plugin); | ||
this.hooks = {}; | ||
this.validKeys = (opts === null || opts === void 0 ? void 0 : opts.validKeys) || []; | ||
} | ||
_createClass(Plugin, [{ | ||
key: "register", | ||
value: function register(plugin) { | ||
var _this = this; | ||
assert(!!plugin.apply, "register failed, plugin.apply must supplied"); | ||
assert(!!plugin.path, "register failed, plugin.path must supplied"); | ||
Object.keys(plugin.apply).forEach(function (key) { | ||
assert(_this.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " from plugin ").concat(plugin.path, ".")); | ||
if (!_this.hooks[key]) _this.hooks[key] = []; | ||
_this.hooks[key] = _this.hooks[key].concat(plugin.apply[key]); | ||
}); | ||
} | ||
}, { | ||
key: "getHooks", | ||
value: function getHooks(keyWithDot) { | ||
var _keyWithDot$split = keyWithDot.split('.'), | ||
_keyWithDot$split2 = _toArray(_keyWithDot$split), | ||
key = _keyWithDot$split2[0], | ||
memberKeys = _keyWithDot$split2.slice(1); | ||
var hooks = this.hooks[key] || []; | ||
if (memberKeys.length) { | ||
hooks = hooks.map(function (hook) { | ||
try { | ||
var ret = hook; | ||
var _iterator = _createForOfIteratorHelper(memberKeys), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var memberKey = _step.value; | ||
ret = ret[memberKey]; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return ret; | ||
} catch (e) { | ||
return null; | ||
} | ||
}).filter(Boolean); | ||
} | ||
return hooks; | ||
} | ||
}, { | ||
key: "applyPlugins", | ||
value: function applyPlugins(_ref2) { | ||
var key = _ref2.key, | ||
type = _ref2.type, | ||
initialValue = _ref2.initialValue, | ||
args = _ref2.args, | ||
async = _ref2.async; | ||
var hooks = this.getHooks(key) || []; | ||
if (args) { | ||
assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object."); | ||
} | ||
switch (type) { | ||
case exports.ApplyPluginsType.modify: | ||
if (async) { | ||
return hooks.reduce( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(memo, hook) { | ||
var ret; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise.")); | ||
if (!isPromiseLike(memo)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.next = 4; | ||
return memo; | ||
case 4: | ||
memo = _context.sent; | ||
case 5: | ||
if (!(typeof hook === 'function')) { | ||
_context.next = 16; | ||
break; | ||
} | ||
ret = hook(memo, args); | ||
if (!isPromiseLike(ret)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
_context.next = 10; | ||
return ret; | ||
case 10: | ||
return _context.abrupt("return", _context.sent); | ||
case 13: | ||
return _context.abrupt("return", ret); | ||
case 14: | ||
_context.next = 21; | ||
break; | ||
case 16: | ||
if (!isPromiseLike(hook)) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.next = 19; | ||
return hook; | ||
case 19: | ||
hook = _context.sent; | ||
case 20: | ||
return _context.abrupt("return", _objectSpread2(_objectSpread2({}, memo), hook)); | ||
case 21: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue)); | ||
} else { | ||
return hooks.reduce(function (memo, hook) { | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object.")); | ||
if (typeof hook === 'function') { | ||
return hook(memo, args); | ||
} else { | ||
// TODO: deepmerge? | ||
return _objectSpread2(_objectSpread2({}, memo), hook); | ||
} | ||
}, initialValue); | ||
} | ||
case exports.ApplyPluginsType.event: | ||
return hooks.forEach(function (hook) { | ||
assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function.")); | ||
hook(args); | ||
}); | ||
case exports.ApplyPluginsType.compose: | ||
return function () { | ||
return _compose({ | ||
fns: hooks.concat(initialValue), | ||
args: args | ||
})(); | ||
}; | ||
} | ||
} | ||
}]); | ||
return Plugin; | ||
}(); | ||
var LoadableContext = /*#__PURE__*/React.createContext(null); | ||
@@ -819,2 +599,246 @@ | ||
function assert(value, message) { | ||
if (!value) throw new Error(message); | ||
} | ||
/** | ||
* whether in browser env | ||
*/ | ||
var isBrowser = function isBrowser() { | ||
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
}; | ||
(function (ApplyPluginsType) { | ||
ApplyPluginsType["compose"] = "compose"; | ||
ApplyPluginsType["modify"] = "modify"; | ||
ApplyPluginsType["event"] = "event"; | ||
})(exports.ApplyPluginsType || (exports.ApplyPluginsType = {})); | ||
function _compose(_ref) { | ||
var fns = _ref.fns, | ||
args = _ref.args; | ||
if (fns.length === 1) { | ||
return fns[0]; | ||
} | ||
var last = fns.pop(); | ||
return fns.reduce(function (a, b) { | ||
return function () { | ||
return b(a, args); | ||
}; | ||
}, last); | ||
} | ||
function isPromiseLike(obj) { | ||
return !!obj && _typeof(obj) === 'object' && typeof obj.then === 'function'; | ||
} | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(opts) { | ||
_classCallCheck(this, Plugin); | ||
this.hooks = {}; | ||
this.validKeys = (opts === null || opts === void 0 ? void 0 : opts.validKeys) || []; | ||
} | ||
_createClass(Plugin, [{ | ||
key: "register", | ||
value: function register(plugin) { | ||
var _this = this; | ||
assert(!!plugin.apply, "register failed, plugin.apply must supplied"); | ||
assert(!!plugin.path, "register failed, plugin.path must supplied"); | ||
Object.keys(plugin.apply).forEach(function (key) { | ||
assert(_this.validKeys.indexOf(key) > -1, "register failed, invalid key ".concat(key, " from plugin ").concat(plugin.path, ".")); | ||
if (!_this.hooks[key]) _this.hooks[key] = []; | ||
_this.hooks[key] = _this.hooks[key].concat(plugin.apply[key]); | ||
}); | ||
} | ||
}, { | ||
key: "getHooks", | ||
value: function getHooks(keyWithDot) { | ||
var _keyWithDot$split = keyWithDot.split('.'), | ||
_keyWithDot$split2 = _toArray(_keyWithDot$split), | ||
key = _keyWithDot$split2[0], | ||
memberKeys = _keyWithDot$split2.slice(1); | ||
var hooks = this.hooks[key] || []; | ||
if (memberKeys.length) { | ||
hooks = hooks.map(function (hook) { | ||
try { | ||
var ret = hook; | ||
var _iterator = _createForOfIteratorHelper(memberKeys), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var memberKey = _step.value; | ||
ret = ret[memberKey]; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return ret; | ||
} catch (e) { | ||
return null; | ||
} | ||
}).filter(Boolean); | ||
} | ||
return hooks; | ||
} | ||
}, { | ||
key: "applyPlugins", | ||
value: function applyPlugins(_ref2) { | ||
var key = _ref2.key, | ||
type = _ref2.type, | ||
initialValue = _ref2.initialValue, | ||
args = _ref2.args, | ||
async = _ref2.async; | ||
var hooks = this.getHooks(key) || []; | ||
if (args) { | ||
assert(_typeof(args) === 'object', "applyPlugins failed, args must be plain object."); | ||
} | ||
switch (type) { | ||
case exports.ApplyPluginsType.modify: | ||
if (async) { | ||
return hooks.reduce( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(memo, hook) { | ||
var ret; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object' || isPromiseLike(hook), "applyPlugins failed, all hooks for key ".concat(key, " must be function, plain object or Promise.")); | ||
if (!isPromiseLike(memo)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.next = 4; | ||
return memo; | ||
case 4: | ||
memo = _context.sent; | ||
case 5: | ||
if (!(typeof hook === 'function')) { | ||
_context.next = 16; | ||
break; | ||
} | ||
ret = hook(memo, args); | ||
if (!isPromiseLike(ret)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
_context.next = 10; | ||
return ret; | ||
case 10: | ||
return _context.abrupt("return", _context.sent); | ||
case 13: | ||
return _context.abrupt("return", ret); | ||
case 14: | ||
_context.next = 21; | ||
break; | ||
case 16: | ||
if (!isPromiseLike(hook)) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.next = 19; | ||
return hook; | ||
case 19: | ||
hook = _context.sent; | ||
case 20: | ||
return _context.abrupt("return", _objectSpread2(_objectSpread2({}, memo), hook)); | ||
case 21: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(), isPromiseLike(initialValue) ? initialValue : Promise.resolve(initialValue)); | ||
} else { | ||
return hooks.reduce(function (memo, hook) { | ||
assert(typeof hook === 'function' || _typeof(hook) === 'object', "applyPlugins failed, all hooks for key ".concat(key, " must be function or plain object.")); | ||
if (typeof hook === 'function') { | ||
return hook(memo, args); | ||
} else { | ||
// TODO: deepmerge? | ||
return _objectSpread2(_objectSpread2({}, memo), hook); | ||
} | ||
}, initialValue); | ||
} | ||
case exports.ApplyPluginsType.event: | ||
return hooks.forEach(function (hook) { | ||
assert(typeof hook === 'function', "applyPlugins failed, all hooks for key ".concat(key, " must be function.")); | ||
hook(args); | ||
}); | ||
case exports.ApplyPluginsType.compose: | ||
return function () { | ||
return _compose({ | ||
fns: hooks.concat(initialValue), | ||
args: args | ||
})(); | ||
}; | ||
} | ||
} | ||
}]); | ||
return Plugin; | ||
}(); | ||
Object.defineProperty(exports, 'createBrowserHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createBrowserHistory; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createHashHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createHashHistory; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createMemoryHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createMemoryHistory; | ||
} | ||
}); | ||
Object.defineProperty(exports, '__RouterContext', { | ||
enumerable: true, | ||
get: function () { | ||
return reactRouter.__RouterContext; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'Link', { | ||
@@ -910,28 +934,4 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, '__RouterContext', { | ||
enumerable: true, | ||
get: function () { | ||
return reactRouter.__RouterContext; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createBrowserHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createBrowserHistory; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createHashHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createHashHistory; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'createMemoryHistory', { | ||
enumerable: true, | ||
get: function () { | ||
return historyWithQuery.createMemoryHistory; | ||
} | ||
}); | ||
exports.Plugin = Plugin; | ||
exports.dynamic = dynamic; | ||
exports.isBrowser = isBrowser; |
{ | ||
"name": "@umijs/runtime", | ||
"version": "3.5.0-beta.4", | ||
"version": "3.5.0-beta.5", | ||
"description": "@umijs/runtime", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |