@v-c/overflow 0.0.1

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.
@@ -0,0 +1,13 @@
1
+ import { Ref } from 'vue';
2
+ type Updater<T> = T | ((origin: T) => T);
3
+ type UpdateCallbackFunc = () => void;
4
+ type NotifyEffectUpdate = (callback: UpdateCallbackFunc) => void;
5
+ /**
6
+ * Batcher for record any useEffectState need update.
7
+ */
8
+ export declare function useBatcher(): NotifyEffectUpdate;
9
+ /**
10
+ * Trigger state update by ref to save perf.
11
+ */
12
+ export default function useEffectState<T>(notifyEffectUpdate: NotifyEffectUpdate, defaultValue?: T | null | undefined): [Ref<T | null | undefined>, (nextValue: Updater<T>) => void];
13
+ export {};
@@ -0,0 +1,37 @@
1
+ import useEvent from "@v-c/util/dist/hooks/useEvent";
2
+ import { ref } from "vue";
3
+ import channelUpdate from "./channelUpdate.js";
4
+ function useBatcher() {
5
+ const updateFuncRef = ref(null);
6
+ const notifyEffectUpdate = (callback) => {
7
+ if (!updateFuncRef.value) {
8
+ updateFuncRef.value = [];
9
+ channelUpdate(() => {
10
+ updateFuncRef.value.forEach((fn) => {
11
+ fn();
12
+ });
13
+ updateFuncRef.value = null;
14
+ });
15
+ }
16
+ updateFuncRef.value.push(callback);
17
+ };
18
+ return notifyEffectUpdate;
19
+ }
20
+ function useEffectState(notifyEffectUpdate, defaultValue) {
21
+ const stateValue = ref(defaultValue);
22
+ const setEffectVal = useEvent((nextValue) => {
23
+ notifyEffectUpdate(() => {
24
+ if (typeof nextValue === "function") {
25
+ const updater = nextValue;
26
+ stateValue.value = updater(stateValue.value);
27
+ } else {
28
+ stateValue.value = nextValue;
29
+ }
30
+ });
31
+ });
32
+ return [stateValue, setEffectVal];
33
+ }
34
+ export {
35
+ useEffectState as default,
36
+ useBatcher
37
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const Overflow = require("./Overflow.cjs");
4
+ const context = require("./context.cjs");
5
+ exports.default = Overflow.default;
6
+ exports.OverflowContextProvider = context.OverflowContextProvider;
@@ -0,0 +1,4 @@
1
+ import { default as Overflow } from './Overflow';
2
+ export { OverflowContextProvider } from './context';
3
+ export type { OverflowProps } from './Overflow';
4
+ export default Overflow;
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import Overflow from "./Overflow.js";
2
+ import { OverflowContextProvider } from "./context.js";
3
+ export {
4
+ OverflowContextProvider,
5
+ Overflow as default
6
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@v-c/overflow",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "overflow",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./dist/*": "./dist/*",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "main": "./dist/index.js",
19
+ "files": [
20
+ "dist",
21
+ "package.json"
22
+ ],
23
+ "peerDependencies": {
24
+ "vue": "^3.0.0"
25
+ },
26
+ "dependencies": {
27
+ "@v-c/resize-observer": "0.0.3",
28
+ "@v-c/util": "0.0.13"
29
+ },
30
+ "scripts": {
31
+ "build": "vite build",
32
+ "prepublish": "pnpm build",
33
+ "test": "vitest run",
34
+ "bump": "bumpp --release patch"
35
+ }
36
+ }