npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

veboundary

v1.2.2

Published

Simple and convenient Vue error boundary.

Downloads

493

Readme

The idea comes fromreact-error-boundary, catch errors thrown by subcomponents and provide a UI for fallback slot when the error is displayed.

Features

  • 🔗 easy, out of the box.
  • 🔧 support devtools.
  • 🔑 type safe.
  • 🔨 unit testing.

Catalogue

Install

Install plugins into dependencies, you can use which you like package manager.

pnpm add veboundary

Usage

<script lang="ts" setup>
import VueErrorBoundary from 'veboundary';
import Son from './son.vue';
import FallbackComponent from './fallback.vue';
</script>

<template>
  <VueErrorBoundary>
    <Son />

    <template #fallback>
      <FallbackComponent />
    </template>
  </VueErrorBoundary>
</template>

Slot Scope

if you want to get error information, you can get it through slot scope. the slot scope provides two variables, one of error:Error. one of reset:() = > void;

reset rerenders the default slot, and you can provide a button in the fallback component to try to rerender

<script lang="ts" setup>
import ErrorBoundary from 'veboundary';
import Son from './son.vue';
import FallbackComponent from './fallback.vue';
</script>

<template>
  <ErrorBoundary>
    <Son />

    <template #fallback="{ error, reset }">
      <FallbackComponent :error="error" :reset="reset" />
    </template>
  </ErrorBoundary>
</template>

Emit

If you want a more detailed error report, you can get it from emit.

<script lang="ts" setup>
import VueErrorBoundary,{VueErrorBoundaryEmit} from 'veboundary';
import Son from './son.vue';
import FallbackComponent, from './fallback.vue';

const caputedEmit: VueErrorBoundaryEmit = function ({ error, instance, info }) {
  console.log(error.message);
};
</script>

<template>
  <VueErrorBoundary @caputred="caputedEmit">
    <Son />

    <template #fallback="errors">
      <FallbackComponent v-bind="errors" />
    </template>
  </VueErrorBoundary>
</template>

Props

propagation

Veboundary captures errors through onErrorCaptured. If you also use onErrorCaptured in the parent component, errors will not be captured. If you want to capture errors in the parent component, you can pass in the propagation prop.

TIPS: If exclude is true, the onErrorCaptured of the parent component must catch errors, even if false is passed in from the propagation.About exclude, we will mention it later.

<script lang="ts" setup>
import VueErrorBoundary from 'veboundary';
import Son from './son.vue';
import FallbackComponent, from './fallback.vue';
</script>

<template>
  <VueErrorBoundary propagation>
    <Son />

    <template #fallback="errors">
      <FallbackComponent v-bind="errors" />
    </template>
  </VueErrorBoundary>
</template>

include-exclude

If you only want to catch some errors, you can pass in include:string[] | RegExp or exclude:string[] | RegExp props.

TIPS: If include or exclude is of type string[], will match error.message and error.name, if include or exclude is of type RegExp, only match error.message

<script lang="ts" setup>
import VueErrorBoundary from 'veboundary';
import Son from './son.vue';
import FallbackComponent, from './fallback.vue';

 const regexp = /^(throwReferenceError|throwError)$/;
 const list = ['network some error', 'TypeError']
</script>

<template>
  <VueErrorBoundary :include="list" :exclude="regexp">
    <Son />

    <template #fallback="errors">
      <FallbackComponent v-bind="errors" />
    </template>
  </VueErrorBoundary>
</template>

keepEmit

If exclude is true, errorCaptured emit will not be triggered. If you want to trigger emit when exclude is true, you can pass in keepEmit.

<script lang="ts" setup>
import VueErrorBoundary,{VueErrorBoundaryEmit} from 'veboundary';
import Son from './son.vue';
import FallbackComponent, from './fallback.vue';

 const regexp = /^(throwReferenceError|throwError)$/;
 const list = ['network some error', 'TypeError']

 const caputedEmit: VueErrorBoundaryEmit = function ({ error, instance, info }) {
  console.log(error.message);
};
</script>

<template>
  <VueErrorBoundary :include="list" :exclude="regexp" @caputred="caputedEmit" keep-emit>
    <Son />

    <template #fallback="errors">
      <FallbackComponent v-bind="errors" />
    </template>
  </VueErrorBoundary>
</template>

Suspense

You can view the examples used with suspense+vue-query in the codesandbox

useBoundary

It is not necessary to obtain reset and error through props,more convenient to use hook.


const {error, reset} = useBoundary();
console.log(error?.message, error?.name);
...

Devtools

Support Vue devtools.You can view the error information and other contents in the developer tool.

You can add an id to the component for marking. If no id is passed in, VeBoundary will automatically generate an id as a mark.Be careful not to duplicate id, data with the same id will be overwritten.

LICENSE

MIT