@pulse-js/vue 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @pulse-js/vue
2
+
3
+ The standard Vue 3 integration for Pulse.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pulse-js/vue.svg)](https://www.npmjs.com/package/@pulse-js/vue)
6
+
7
+ ## Features
8
+
9
+ - **Composable API**: `usePulse` returns standard Vue `Ref` or `ComputedRef` objects.
10
+ - **Reactive Unwrapping**: Use `.value` or unwrapping in templates just like native Vue signals.
11
+ - **Type Safety**: Full TypeScript support.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @pulse-js/core @pulse-js/vue
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Using Sources
22
+
23
+ Map Pulse sources to Vue definitions.
24
+
25
+ ```vue
26
+ <script setup lang="ts">
27
+ import { source } from "@pulse-js/core";
28
+ import { usePulse } from "@pulse-js/vue";
29
+
30
+ const count = source(0);
31
+ // Returns a Ref<number>
32
+ const countRef = usePulse(count);
33
+
34
+ function increment() {
35
+ count.set(count.value + 1);
36
+ }
37
+ </script>
38
+
39
+ <template>
40
+ <button @click="increment">Count is {{ countRef }}</button>
41
+ </template>
42
+ ```
43
+
44
+ ### Using Guards
45
+
46
+ Guards are mapped to DeepReadonly Refs containing the full state.
47
+
48
+ ```vue
49
+ <script setup lang="ts">
50
+ import { guard } from "@pulse-js/core";
51
+ import { usePulse } from "@pulse-js/vue";
52
+
53
+ const isAdult = guard(() => age.value >= 18);
54
+ const state = usePulse(isAdult);
55
+ // state is Ref<GuardState<boolean>>
56
+ </script>
57
+
58
+ <template>
59
+ <div v-if="state.status === 'ok'">Allowed: {{ state.value }}</div>
60
+ <div v-else-if="state.status === 'fail'">Blocked: {{ state.reason }}</div>
61
+ </template>
62
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useGuard: () => useGuard,
24
+ usePulse: () => usePulse
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_vue = require("vue");
28
+ function usePulse(unit) {
29
+ const isGuard = unit !== null && typeof unit === "function" && "state" in unit;
30
+ const state = (0, import_vue.shallowRef)(isGuard ? unit.state() : unit());
31
+ const unsub = unit.subscribe((newVal) => {
32
+ state.value = newVal;
33
+ });
34
+ (0, import_vue.onUnmounted)(unsub);
35
+ return state;
36
+ }
37
+ function useGuard(guard) {
38
+ return usePulse(guard);
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ useGuard,
43
+ usePulse
44
+ });
@@ -0,0 +1,14 @@
1
+ import { Ref } from 'vue';
2
+ import { Source, Guard, GuardState } from '@pulse-js/core';
3
+
4
+ /**
5
+ * Hook to consume a Pulse Unit (Source or Guard) in a Vue component.
6
+ */
7
+ declare function usePulse<T>(unit: Source<T>): Ref<T>;
8
+ declare function usePulse<T>(unit: Guard<T>): Ref<GuardState<T>>;
9
+ /**
10
+ * Explicit hook for Pulse Guards in Vue.
11
+ */
12
+ declare function useGuard<T>(guard: Guard<T>): Ref<GuardState<T>>;
13
+
14
+ export { useGuard, usePulse };
@@ -0,0 +1,14 @@
1
+ import { Ref } from 'vue';
2
+ import { Source, Guard, GuardState } from '@pulse-js/core';
3
+
4
+ /**
5
+ * Hook to consume a Pulse Unit (Source or Guard) in a Vue component.
6
+ */
7
+ declare function usePulse<T>(unit: Source<T>): Ref<T>;
8
+ declare function usePulse<T>(unit: Guard<T>): Ref<GuardState<T>>;
9
+ /**
10
+ * Explicit hook for Pulse Guards in Vue.
11
+ */
12
+ declare function useGuard<T>(guard: Guard<T>): Ref<GuardState<T>>;
13
+
14
+ export { useGuard, usePulse };
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // src/index.ts
2
+ import { shallowRef, onUnmounted } from "vue";
3
+ function usePulse(unit) {
4
+ const isGuard = unit !== null && typeof unit === "function" && "state" in unit;
5
+ const state = shallowRef(isGuard ? unit.state() : unit());
6
+ const unsub = unit.subscribe((newVal) => {
7
+ state.value = newVal;
8
+ });
9
+ onUnmounted(unsub);
10
+ return state;
11
+ }
12
+ function useGuard(guard) {
13
+ return usePulse(guard);
14
+ }
15
+ export {
16
+ useGuard,
17
+ usePulse
18
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@pulse-js/vue",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "bun x tsup src/index.ts --format esm,cjs --dts --clean --external vue,@pulse-js/core",
13
+ "lint": "bun x tsc --noEmit"
14
+ },
15
+ "peerDependencies": {
16
+ "vue": "^3.5.0"
17
+ },
18
+ "dependencies": {
19
+ "@pulse-js/core": "^0.1.8"
20
+ },
21
+ "devDependencies": {
22
+ "vue": "^3.5.0",
23
+ "tsup": "^8.0.0",
24
+ "typescript": "^5.0.0"
25
+ }
26
+ }