@globalbrain/sefirot
Advanced tools
Comparing version 0.42.0 to 0.43.0
@@ -0,1 +1,7 @@ | ||
# [0.43.0](https://github.com/globalbrain/sefirot/compare/v0.42.0...v0.43.0) (2021-03-01) | ||
### Features | ||
* add ability to take callback in `computedIfOnly` helper function ([82cb14d](https://github.com/globalbrain/sefirot/commit/82cb14df6c2225246345b794b7f22b3724c01300)) | ||
# [0.42.0](https://github.com/globalbrain/sefirot/compare/v0.41.0...v0.42.0) (2021-02-26) | ||
@@ -2,0 +8,0 @@ |
@@ -5,4 +5,12 @@ import { Ref, ComputedRef, UnwrapRef, ref, computed, watch, isRef } from '@vue/composition-api' | ||
export function get<T>(refish: Refish<T>): T { | ||
return isRef(refish) ? refish.value : refish | ||
export function get<T>(refish: Refish<T> | (() => T)): T { | ||
if (isRef(refish)) { | ||
return refish.value | ||
} | ||
if (refish instanceof Function) { | ||
return refish() | ||
} | ||
return refish | ||
} | ||
@@ -23,3 +31,3 @@ | ||
export function computedIfOnly<T, R, E>( | ||
refish: Ref<T | null> | ComputedRef<T | null>, | ||
refish: Ref<T | null> | ComputedRef<T | null> | (() => T | null), | ||
callback: (value: T) => R, | ||
@@ -30,4 +38,6 @@ empty: E | ||
if (refish.value) { | ||
value.value = callback(refish.value) as UnwrapRef<R> | ||
const refValue = get(refish) | ||
if (refValue) { | ||
value.value = callback(refValue) as UnwrapRef<R> | ||
} | ||
@@ -34,0 +44,0 @@ |
{ | ||
"name": "@globalbrain/sefirot", | ||
"version": "0.42.0", | ||
"version": "0.43.0", | ||
"description": "Vue Components for Global Brain Design System.", | ||
@@ -5,0 +5,0 @@ "files": [ |
275357
1742