create-app
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -9,7 +9,9 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /** | ||
* createApp at client | ||
*/ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** | ||
* createApp at client | ||
*/ | ||
exports.default = createApp; | ||
@@ -55,4 +57,7 @@ | ||
var container = finalAppSettings.container; | ||
var cacheAmount = finalAppSettings.cacheAmount; | ||
context = _extends({}, finalAppSettings.context, appSettings.context); | ||
var history = createHistory(finalAppSettings); | ||
@@ -65,2 +70,20 @@ var matcher = (0, _createMatcher2.default)(routes); | ||
var cache = _.createCache(cacheAmount); | ||
function saveControllerToCache(controller) { | ||
if (controller.KeepAlive === true) { | ||
cache.set(controller.location.raw, controller); | ||
} else { | ||
cache.remove(controller.location.raw); | ||
} | ||
} | ||
function getControllerFromCache(location) { | ||
return cache.get(location.raw); | ||
} | ||
function removeControllerFromCache(controller) { | ||
cache.remove(controller.location.raw); | ||
} | ||
function _getContainer() { | ||
@@ -97,3 +120,3 @@ if (finalContainer) { | ||
location.params = params; | ||
location.raw = location.pathname + location.search + location.hash; | ||
location.raw = location.pathname + location.search; | ||
@@ -154,2 +177,13 @@ var controllerType = typeof controller === 'undefined' ? 'undefined' : _typeof(controller); | ||
} | ||
}, { | ||
key: 'saveToCache', | ||
value: function saveToCache() { | ||
this.KeepAlive = true; | ||
saveControllerToCache(this); | ||
} | ||
}, { | ||
key: 'removeFromCache', | ||
value: function removeFromCache() { | ||
removeControllerFromCache(this); | ||
} | ||
}]); | ||
@@ -172,7 +206,16 @@ | ||
var FinalController = getController(location.pattern, Controller); | ||
var controller = currentController = new FinalController(location, context); | ||
var component = controller.init(); | ||
var controller = currentController = getControllerFromCache(location); | ||
var component = null; | ||
// if controller.init return false value, do nothing | ||
if (controller) { | ||
component = controller.restore(location, context); | ||
controller.location = location; | ||
controller.context = context; | ||
} else { | ||
var FinalController = getController(location.pattern, Controller); | ||
controller = currentController = new FinalController(location, context); | ||
component = controller.init(); | ||
} | ||
// if controller#init|restore return false value, do nothing | ||
if (component == null) { | ||
@@ -187,6 +230,7 @@ return null; | ||
} | ||
saveControllerToCache(controller); | ||
return renderToContainer(result); | ||
}); | ||
} | ||
saveControllerToCache(controller); | ||
return renderToContainer(component); | ||
@@ -193,0 +237,0 @@ }; |
@@ -59,2 +59,4 @@ 'use strict'; | ||
context = _extends({}, finalAppSettings.context, appSettings.context); | ||
var matcher = (0, _createMatcher2.default)(routes); | ||
@@ -61,0 +63,0 @@ var history = createHistory(finalAppSettings); |
@@ -14,3 +14,6 @@ 'use strict'; | ||
basename: '', | ||
context: {}, | ||
context: { | ||
isServer: isServer, | ||
isClient: isClient | ||
}, | ||
type: 'createHashHistory', | ||
@@ -17,0 +20,0 @@ loader: function loader(value) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
exports.extend = extend; | ||
exports.isAbsoluteUrl = isAbsoluteUrl; | ||
exports.createCache = createCache; | ||
// util | ||
@@ -32,12 +32,35 @@ function isThenable(obj) { | ||
function isAbsoluteUrl(url) { | ||
if (typeof url !== 'string') { | ||
throw new Error('expected url to be a string'); | ||
function createCache() { | ||
var amount = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0]; | ||
var cache = {}; | ||
function keys() { | ||
return Object.keys(cache); | ||
} | ||
if (url.charAt(0) === '/' && url.charAt(1) === '/') { | ||
return true; | ||
function checkAmount() { | ||
var cacheKeys = keys(cache); | ||
if (cacheKeys.length > amount) { | ||
remove(cacheKeys[0]); | ||
} | ||
} | ||
var str1 = url.charAt(0) + url.charAt(1); | ||
var str2 = str1 + url.charAt(2) + url.charAt(3); | ||
return str1 === '//' || str2 === 'http'; | ||
function set(key, value) { | ||
remove(key); | ||
cache[key] = value; | ||
checkAmount(); | ||
} | ||
function get(key) { | ||
return cache[key]; | ||
} | ||
function remove(key) { | ||
if (cache.hasOwnProperty(key)) { | ||
delete cache[key]; | ||
} | ||
} | ||
return { keys: keys, get: get, set: set, remove: remove }; | ||
} | ||
@@ -44,0 +67,0 @@ |
{ | ||
"name": "create-app", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "configuring once, rendering both client and server.", | ||
@@ -5,0 +5,0 @@ "browser": "lib/client/index.js", |
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
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
31776
698