@aesoper/hooks
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -8,2 +8,3 @@ "use strict"; | ||
const index$3 = require("./use-memo/index.js"); | ||
const index$4 = require("./use-boolean/index.js"); | ||
exports.defaultNamespace = index.defaultNamespace; | ||
@@ -16,1 +17,2 @@ exports.namespaceContextKey = index.namespaceContextKey; | ||
exports.useMemo = index$3.useMemo; | ||
exports.useBoolean = index$4.useBoolean; |
@@ -78,2 +78,10 @@ (function(global, factory) { | ||
}; | ||
function useState(defaultStateValue) { | ||
const initValue = typeof defaultStateValue === "function" ? defaultStateValue() : defaultStateValue; | ||
const innerValue = vue.ref(initValue); | ||
function triggerChange(newValue) { | ||
innerValue.value = newValue; | ||
} | ||
return [innerValue, triggerChange]; | ||
} | ||
function createContext(defaultValue) { | ||
@@ -117,5 +125,18 @@ const contextKey = Symbol("contextKey"); | ||
} | ||
function useBoolean(initialState = false) { | ||
const [value, setValue] = useState(initialState); | ||
const callbacks = useMemo( | ||
() => ({ | ||
on: () => setValue(true), | ||
off: () => setValue(false), | ||
toggle: () => setValue(!value.value) | ||
}), | ||
[] | ||
); | ||
return [value, callbacks]; | ||
} | ||
exports2.createContext = createContext; | ||
exports2.defaultNamespace = defaultNamespace; | ||
exports2.namespaceContextKey = namespaceContextKey; | ||
exports2.useBoolean = useBoolean; | ||
exports2.useDestroyed = useDestroyed; | ||
@@ -122,0 +143,0 @@ exports2.useGetDerivedNamespace = useGetDerivedNamespace; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Hooks={},e.Vue)}(this,(function(e,t){"use strict";const n="bee",o=(e,t,n,o,u)=>{let s=`${e}-${t}`;return n&&(s+=`-${n}`),o&&(s+=`__${o}`),u&&(s+=`--${u}`),s},u=Symbol("namespaceContextKey"),s=e=>{const o=e||(t.getCurrentInstance()?t.inject(u,t.ref(n)):t.ref(n));return t.computed((()=>t.unref(o)||n))};e.createContext=function(e){const n=Symbol("contextKey");return{useProvide:(e,o)=>{const u=t.reactive({});return t.provide(n,u),t.watchEffect((()=>{Object.assign(u,e,o||{})})),u},useInject:()=>t.inject(n,e)||{}}},e.defaultNamespace=n,e.namespaceContextKey=u,e.useDestroyed=()=>{const e=t.shallowRef(!1);return t.onBeforeUnmount((()=>{e.value=!0})),e},e.useGetDerivedNamespace=s,e.useMemo=function(e,n,o){const u=t.ref(e());return t.watch(n,((t,n)=>{o?o(t,n)&&(u.value=e()):u.value=e()})),u},e.useNamespace=(e,t)=>{const n=s(t);return{namespace:n,b:(t="")=>o(n.value,e,t,"",""),e:t=>t?o(n.value,e,"",t,""):"",m:t=>t?o(n.value,e,"","",t):"",be:(t,u)=>t&&u?o(n.value,e,t,u,""):"",em:(t,u)=>t&&u?o(n.value,e,"",t,u):"",bm:(t,u)=>t&&u?o(n.value,e,t,"",u):"",bem:(t,u,s)=>t&&u&&s?o(n.value,e,t,u,s):"",is:(e,...t)=>{const n=!(t.length>=1)||t[0];return e&&n?`is-${e}`:""},cssVar:e=>{const t={};for(const o in e)e[o]&&(t[`--${n.value}-${o}`]=e[o]);return t},cssVarName:e=>`--${n.value}-${e}`,cssVarBlock:t=>{const o={};for(const u in t)t[u]&&(o[`--${n.value}-${e}-${u}`]=t[u]);return o},cssVarBlockName:t=>`--${n.value}-${e}-${t}`}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Hooks={},e.Vue)}(this,(function(e,t){"use strict";const n="bee",o=(e,t,n,o,u)=>{let r=`${e}-${t}`;return n&&(r+=`-${n}`),o&&(r+=`__${o}`),u&&(r+=`--${u}`),r},u=Symbol("namespaceContextKey"),r=e=>{const o=e||(t.getCurrentInstance()?t.inject(u,t.ref(n)):t.ref(n));return t.computed((()=>t.unref(o)||n))};function s(e,n,o){const u=t.ref(e());return t.watch(n,((t,n)=>{o?o(t,n)&&(u.value=e()):u.value=e()})),u}e.createContext=function(e){const n=Symbol("contextKey");return{useProvide:(e,o)=>{const u=t.reactive({});return t.provide(n,u),t.watchEffect((()=>{Object.assign(u,e,o||{})})),u},useInject:()=>t.inject(n,e)||{}}},e.defaultNamespace=n,e.namespaceContextKey=u,e.useBoolean=function(e=!1){const[n,o]=function(e){const n="function"==typeof e?e():e,o=t.ref(n);return[o,function(e){o.value=e}]}(e),u=s((()=>({on:()=>o(!0),off:()=>o(!1),toggle:()=>o(!n.value)})),[]);return[n,u]},e.useDestroyed=()=>{const e=t.shallowRef(!1);return t.onBeforeUnmount((()=>{e.value=!0})),e},e.useGetDerivedNamespace=r,e.useMemo=s,e.useNamespace=(e,t)=>{const n=r(t);return{namespace:n,b:(t="")=>o(n.value,e,t,"",""),e:t=>t?o(n.value,e,"",t,""):"",m:t=>t?o(n.value,e,"","",t):"",be:(t,u)=>t&&u?o(n.value,e,t,u,""):"",em:(t,u)=>t&&u?o(n.value,e,"",t,u):"",bm:(t,u)=>t&&u?o(n.value,e,t,"",u):"",bem:(t,u,r)=>t&&u&&r?o(n.value,e,t,u,r):"",is:(e,...t)=>{const n=!(t.length>=1)||t[0];return e&&n?`is-${e}`:""},cssVar:e=>{const t={};for(const o in e)e[o]&&(t[`--${n.value}-${o}`]=e[o]);return t},cssVarName:e=>`--${n.value}-${e}`,cssVarBlock:t=>{const o={};for(const u in t)t[u]&&(o[`--${n.value}-${e}-${u}`]=t[u]);return o},cssVarBlockName:t=>`--${n.value}-${e}-${t}`}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})})); | ||
//# sourceMappingURL=hooks.min.js.map |
@@ -6,2 +6,3 @@ import { defaultNamespace, namespaceContextKey, useGetDerivedNamespace, useNamespace } from "./use-namespace/index.js"; | ||
import { useMemo } from "./use-memo/index.js"; | ||
import { useBoolean } from "./use-boolean/index.js"; | ||
export { | ||
@@ -11,2 +12,3 @@ createContext, | ||
namespaceContextKey, | ||
useBoolean, | ||
useDestroyed, | ||
@@ -13,0 +15,0 @@ useGetDerivedNamespace, |
@@ -8,2 +8,3 @@ "use strict"; | ||
const index$3 = require("./use-memo/index.js"); | ||
const index$4 = require("./use-boolean/index.js"); | ||
exports.defaultNamespace = index.defaultNamespace; | ||
@@ -16,1 +17,2 @@ exports.namespaceContextKey = index.namespaceContextKey; | ||
exports.useMemo = index$3.useMemo; | ||
exports.useBoolean = index$4.useBoolean; |
{ | ||
"name": "@aesoper/hooks", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "> TODO: description", | ||
@@ -43,6 +43,7 @@ "homepage": "https://github.com/aesoper101/vue3use#readme", | ||
"dependencies": { | ||
"@vueuse/core": "^10.7.2", | ||
"vue": "^3.4.15" | ||
}, | ||
"devDependencies": { | ||
"@aesoper/build-cli": "^1.1.15", | ||
"@aesoper/build-cli": "^1.1.16", | ||
"@tsconfig/node18": "^18.2.2", | ||
@@ -52,2 +53,3 @@ "@vue/tsconfig": "^0.5.1" | ||
"peerDependencies": { | ||
"@vueuse/core": "^10.7.2", | ||
"vue": "^3.3.10" | ||
@@ -59,5 +61,5 @@ }, | ||
}, | ||
"gitHead": "5046f72060482aea6da8b73ebf2dcbb93695a3b0", | ||
"gitHead": "6044d0b66a320bf6a484e83cfc339b346a72fa69", | ||
"readme": "ERROR: No README data found!", | ||
"_id": "@aesoper/hooks@1.0.10" | ||
"_id": "@aesoper/hooks@1.0.16" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42915
30
579
4
+ Added@vueuse/core@^10.7.2
+ Added@types/web-bluetooth@0.0.20(transitive)
+ Added@vueuse/core@10.11.1(transitive)
+ Added@vueuse/metadata@10.11.1(transitive)
+ Added@vueuse/shared@10.11.1(transitive)
+ Addedvue-demi@0.14.10(transitive)