@vingy/vuebugger 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +47 -2
  2. package/dist/index.mjs +34 -13
  3. package/package.json +10 -1
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # vue-composable-devtools
1
+ # Vuebugger
2
2
 
3
- Vue devtools for composables
3
+ Vue devtools provide an easy way to inspect component state. But when having something like a composable, you actually need to catch all the returned values in order for them to show up in the devtools. This is where this package can come in handy.
4
+
5
+ ## Features
6
+
7
+ - Debug composables and reactive state easily
8
+ - Tree-shakable with zero runtime overhead
9
+ - Simple API: just call `debug(name, state)`
10
+
11
+ ## Quick start
12
+
13
+ ```bash
14
+ pnpm add -D @vingy/vuebugger
15
+ ```
16
+
17
+ Register the plugin in your app:
18
+
19
+ ```ts
20
+ import Vuebugger from '@vingy/vuebugger'
21
+
22
+ createApp(App).use(Vuebugger)
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ `debug()` registers values from composables so they show up in Vue Devtools.
28
+
29
+ ```ts
30
+ import { debug } from '@vingy/vuebugger'
31
+
32
+ export const useFoo = (initial: number) => {
33
+ const multiplier = ref(1) // not easy to debug if something goes wrong
34
+
35
+ const inc = () => multiplier.value++
36
+ const dec = () => multiplier.value--
37
+
38
+ const value = computed(() => initial * multiplier)
39
+
40
+ debug('useFoo', { multiplier }) // now visible in devtools
41
+
42
+ return { value, inc, dec }
43
+ }
44
+ ```
45
+
46
+ See the demo app in [demo/](demo).
47
+
48
+ > **Note:** This plugin is tree-shakable and has zero runtime overhead when `debug()` calls are not used.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentInstance, toValue, watch } from "vue";
1
+ import { getCurrentInstance, getCurrentScope, onBeforeUnmount, toValue, watch } from "vue";
2
2
 
3
3
  //#region node_modules/.pnpm/@vue+devtools-shared@8.0.5/node_modules/@vue/devtools-shared/dist/index.js
4
4
  var __create$1 = Object.create;
@@ -3784,10 +3784,10 @@ const MAX_SERIALIZED_SIZE = 2 * 1024 * 1024;
3784
3784
  const byUid = /* @__PURE__ */ new Map();
3785
3785
  const byGroupId = /* @__PURE__ */ new Map();
3786
3786
  const callbacks = [];
3787
- const runCallbacks = (componentInstance) => callbacks.forEach((cb) => cb(componentInstance));
3787
+ const runCallbacks = (entry) => callbacks.forEach((cb) => cb(entry));
3788
3788
  const withCallbacks = (fn) => (entry) => {
3789
3789
  fn(entry);
3790
- runCallbacks(entry.componentInstance);
3790
+ runCallbacks(entry);
3791
3791
  };
3792
3792
  const upsert = withCallbacks((entry) => {
3793
3793
  const { uid, groupId } = entry;
@@ -3795,6 +3795,7 @@ const upsert = withCallbacks((entry) => {
3795
3795
  const group = byGroupId.get(groupId);
3796
3796
  if (!group) byGroupId.set(groupId, new Set([uid]));
3797
3797
  else group.add(uid);
3798
+ console.log("upsert");
3798
3799
  });
3799
3800
  const remove = withCallbacks((entry) => {
3800
3801
  const { uid, groupId } = entry;
@@ -3802,6 +3803,7 @@ const remove = withCallbacks((entry) => {
3802
3803
  const group = byGroupId.get(groupId);
3803
3804
  group?.delete(uid);
3804
3805
  if (group?.size === 0) byGroupId.delete(groupId);
3806
+ console.log("remove");
3805
3807
  });
3806
3808
  const onUpdate = (fn) => {
3807
3809
  callbacks.push(fn);
@@ -3809,7 +3811,8 @@ const onUpdate = (fn) => {
3809
3811
 
3810
3812
  //#endregion
3811
3813
  //#region src/devtools.ts
3812
- const INSPECTOR_ID = "composables";
3814
+ const INSPECTOR_ID = "vuebugger-inspector";
3815
+ const TIMELINE_ID = "vuebugger-timeline";
3813
3816
  const handleGetInspectorTree = (payload) => {
3814
3817
  if (payload.inspectorId === INSPECTOR_ID) {
3815
3818
  const term = payload.filter;
@@ -3874,10 +3877,25 @@ function setupComposableDevtools(app) {
3874
3877
  icon: "https://raw.githubusercontent.com/vinpogo/vuebugger/main/logo.png",
3875
3878
  treeFilterPlaceholder: "Search by composable or component name..."
3876
3879
  });
3877
- onUpdate((componentInstance) => {
3880
+ api.addTimelineLayer({
3881
+ id: TIMELINE_ID,
3882
+ label: "Vuebugger",
3883
+ color: 155
3884
+ });
3885
+ onUpdate((entry) => {
3878
3886
  api.sendInspectorTree(INSPECTOR_ID);
3879
3887
  api.sendInspectorState(INSPECTOR_ID);
3880
- api.notifyComponentUpdate(componentInstance);
3888
+ api.notifyComponentUpdate(entry.componentInstance);
3889
+ api.addTimelineEvent({
3890
+ layerId: TIMELINE_ID,
3891
+ event: {
3892
+ time: api.now(),
3893
+ data: entry,
3894
+ title: `${entry.uid} state change`,
3895
+ groupId: entry.uid,
3896
+ meta: { vin: "was here" }
3897
+ }
3898
+ });
3881
3899
  });
3882
3900
  api.on.getInspectorTree(handleGetInspectorTree);
3883
3901
  api.on.getInspectorState(handleGetInspectorState(api));
@@ -3892,24 +3910,27 @@ function debug(groupId, state) {
3892
3910
  const instance = getCurrentInstance();
3893
3911
  const componentName = instance?.type.name || instance?.type.__name || "No component";
3894
3912
  const uid = `${componentName}/${groupId}-${Math.random().toString(36).slice(2, 9)}`;
3895
- watch(() => state, (value, _, onCleanup) => {
3896
- upsert({
3913
+ getCurrentScope()?.run(() => {
3914
+ onBeforeUnmount(() => remove({
3897
3915
  groupId,
3898
3916
  uid,
3899
3917
  componentName,
3900
3918
  componentInstance: instance,
3901
- debugState: value
3902
- });
3903
- onCleanup(() => {
3904
- remove({
3919
+ debugState: state
3920
+ }));
3921
+ watch(() => state, (value, _) => {
3922
+ upsert({
3905
3923
  groupId,
3906
3924
  uid,
3907
3925
  componentName,
3908
3926
  componentInstance: instance,
3909
3927
  debugState: value
3910
3928
  });
3929
+ }, {
3930
+ immediate: true,
3931
+ deep: true
3911
3932
  });
3912
- }, { deep: true });
3933
+ });
3913
3934
  return state;
3914
3935
  }
3915
3936
 
package/package.json CHANGED
@@ -1,13 +1,22 @@
1
1
  {
2
2
  "name": "@vingy/vuebugger",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Vue devtools plugin to debug anything.",
5
5
  "keywords": [
6
+ "composable",
7
+ "composition-api",
8
+ "debugging",
6
9
  "devtools",
10
+ "plugin",
11
+ "state",
7
12
  "vue"
8
13
  ],
9
14
  "license": "MIT",
10
15
  "author": "vingy",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/vinpogo/vuebugger"
19
+ },
11
20
  "files": [
12
21
  "dist"
13
22
  ],