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

@badrap/preload

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@badrap/preload - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

2

dist/index.js

@@ -1,2 +0,2 @@

var e={functional:!0,props:["status","error"],render:function(e,r){return e("div",{},[r.props.status+" "+r.props.error.message])}},r={},n={};function t(e,n){return void 0===e&&(e=404),void 0===n&&(n="Not found"),{$type:r,status:e,error:n instanceof Error?n:{message:n}}}function o(e){return{$type:n,to:e}}module.exports=function(u,i){void 0===i&&(i={});var s=i.context;void 0===s&&(s={});var c=i.errorComponent;void 0===c&&(c=e);var a,f=i.beforePreload,l=i.afterPreload,p=Symbol();function d(e,u,i){var d=null,h={};Promise.resolve().then(function(){return f&&f(),function e(r,n,t){return n>=r.length?Promise.resolve():Promise.resolve(t(r[n])).then(function(){return e(r,n+1,t)})}(e.matched,0,function(u){var i=u.meta[p];if(!d&&i)return i().then(function(u){var i=u.key,c=u.preload;if(c)return Promise.resolve(c(Object.assign({},{route:e,redirect:o,error:t},s))).then(function(e){!e||e.$type!==n&&e.$type!==r?h[i]=e:d=e})})}).then(function(){l&&l()},function(e){throw l&&l(),e}).then(function(){if(d){if(d.$type!==r){if(d.$type===n)return d.to;throw new Error("unknown action")}a={render:function(e){return e(c,{props:{status:d.status,error:d.error}})}}}else a={provide:function(){var e;return(e={})[p]=h,e},render:function(e){return e("router-view",{attrs:this.$attrs})}}})}).then(i,i)}return[{path:"",component:{beforeRouteEnter:d,beforeRouteUpdate:d,render:function(e){return e(a,{key:this.$route.fullPath,attrs:this.$attrs})}},children:function e(r,n){return r.map(function(r){return n(Object.assign({},r,{children:r.children&&e(r.children,n)}))})}(u,function(e){var r,n=null,t=function(){var r;return n||(n=(r=e.component,"function"!=typeof r?Promise.resolve(r):new Promise(function(e,n){Promise.resolve(r(e,n)).then(e,n)}).then(function(e){return e.__esModule?e.default:e})).then(function(e){if(!e.preload)return{key:null,preload:null,component:e};var r=Symbol();return{key:r,preload:e.preload,component:{extends:e,inject:{$preload:p},data:function(){return Object.assign({},this.$preload[r])}}}},function(e){return n=null,Promise.reject(e)})),n};return Object.assign({},e,{meta:Object.assign({},e.meta,(r={},r[p]=t,r)),component:function(){return t().then(function(e){return e.component})}})})}]};
var r={functional:!0,props:["status","error"],render:function(r,e){return r("div",{},[e.props.status+" "+e.props.error.message])}},e={},n={};function t(r,n){return void 0===r&&(r=404),void 0===n&&(n="Not found"),{$type:e,status:r,error:n instanceof Error?n:{message:n}}}function o(r){return{$type:n,to:r}}function u(r){return"function"!=typeof r?Promise.resolve(r):new Promise(function(e,n){Promise.resolve(r(e,n)).then(e,n)}).then(function(r){return r.__esModule?r.default:r})}module.exports=function(i,s){void 0===s&&(s={});var c=s.context;void 0===c&&(c={});var a=s.errorComponent;void 0===a&&(a=r);var f,l=s.beforePreload,d=s.afterPreload,p=Symbol();function h(r,i,s){var h=null,v={};Promise.resolve().then(function(){return l&&l(),function r(e,n,t){return n>=e.length?Promise.resolve():Promise.resolve(t(e[n])).then(function(){return r(e,n+1,t)})}(r.matched,0,function(i){if(!h)return u(i.components.default).then(function(u){if(u[p]){var i=u[p],s=i.key;return Promise.resolve((0,i.preload)(Object.assign({},{route:r,redirect:o,error:t},c))).then(function(r){!r||r.$type!==n&&r.$type!==e?v[s]=r:h=r})}})}).then(function(){d&&d()},function(r){throw d&&d(),r}).then(function(){if(h){if(h.$type!==e){if(h.$type===n)return h.to;throw new Error("unknown action")}f={render:function(r){return r(a,{props:{status:h.status,error:h.error}})}}}else f={provide:function(){var r;return(r={})[p]=v,r},render:function(r){return r("router-view",{attrs:this.$attrs})}}})}).then(s,s)}return[{path:"",component:{beforeRouteEnter:h,beforeRouteUpdate:h,render:function(r){return r(f,{key:this.$route.fullPath,attrs:this.$attrs})}},children:function r(e,n){return e.map(function(e){return n(Object.assign({},e,{children:e.children&&r(e.children,n)}))})}(i,function(r){var e=null;return Object.assign({},r,{component:function(){return e||(e=u(r.component).then(function(r){var e;if(!r.preload)return r;var n=Symbol();return(e={extends:r})[p]={key:n,preload:r.preload},e.inject={$preload:p},e.data=function(){return Object.assign({},this.$preload[n])},e},function(r){return e=null,Promise.reject(r)})),e}})})}]};
//# sourceMappingURL=index.js.map
{
"name": "@badrap/preload",
"version": "0.0.6",
"version": "0.0.7",
"description": "Data preloading for vue-router, similar to Sapper's preload or Nuxt.js's asyncData",

@@ -17,7 +17,7 @@ "main": "dist/index.js",

"devDependencies": {
"eslint": "^5.10.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.0.0",
"microbundle": "^0.8.3",
"prettier": "^1.15.3"
"eslint": "^5.15.1",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"microbundle": "^0.11.0",
"prettier": "^1.16.4"
},

@@ -24,0 +24,0 @@ "keywords": [

@@ -66,16 +66,16 @@ function mapRoutes(routes, func) {

if (!resolved.preload) {
return { key: null, preload: null, component: resolved };
return resolved;
}
const key = Symbol();
return {
key,
preload: resolved.preload,
component: {
extends: resolved,
inject: {
$preload: preloadKey
},
data() {
return { ...this.$preload[key] };
}
extends: resolved,
[preloadKey]: {
key,
preload: resolved.preload
},
inject: {
$preload: preloadKey
},
data() {
return { ...this.$preload[key] };
}

@@ -95,9 +95,3 @@ };

...route,
meta: {
...route.meta,
[preloadKey]: cachedPrepare
},
component() {
return cachedPrepare().then(({ component }) => component);
}
component: cachedPrepare
};

@@ -127,22 +121,22 @@ });

return iterate(to.matched, 0, route => {
const prepare = route.meta[preloadKey];
if (action || !prepare) {
if (action) {
return;
}
return prepare().then(({ key, preload }) => {
if (preload) {
return Promise.resolve(
preload({ route: to, redirect, error, ...context })
).then(data => {
if (
data &&
(data.$type === ACTION_REDIRECT ||
data.$type === ACTION_ERROR)
) {
action = data;
} else {
datas[key] = data;
}
});
return componentPromise(route.components.default).then(component => {
if (!component[preloadKey]) {
return;
}
const { key, preload } = component[preloadKey];
return Promise.resolve(
preload({ route: to, redirect, error, ...context })
).then(data => {
if (
data &&
(data.$type === ACTION_REDIRECT || data.$type === ACTION_ERROR)
) {
action = data;
} else {
datas[key] = data;
}
});
});

@@ -149,0 +143,0 @@ })

Sorry, the diff of this file is not supported yet

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