@globalbrain/sefirot
Advanced tools
Comparing version 0.53.0 to 0.53.1
@@ -0,1 +1,8 @@ | ||
## [0.53.1](https://github.com/globalbrain/sefirot/compare/v0.53.0...v0.53.1) (2021-05-13) | ||
### Bug Fixes | ||
* **input-text:** clearable & disabled should not conflict ([#70](https://github.com/globalbrain/sefirot/issues/70)) ([#71](https://github.com/globalbrain/sefirot/issues/71)) ([bf6fd4e](https://github.com/globalbrain/sefirot/commit/bf6fd4e5f074354f942179a1881af18c5c52f9d5)) | ||
* **utils:** return shallow ref from computed utils ([#72](https://github.com/globalbrain/sefirot/issues/72)) ([cbd60c9](https://github.com/globalbrain/sefirot/commit/cbd60c983df823b5a7f0af8ff303e7037f570cb1)) | ||
# [0.53.0](https://github.com/globalbrain/sefirot/compare/v0.52.0...v0.53.0) (2021-05-11) | ||
@@ -2,0 +9,0 @@ |
@@ -1,2 +0,10 @@ | ||
import { Ref, ComputedRef, UnwrapRef, ref, computed, watch, isRef } from '@vue/composition-api' | ||
import { | ||
Ref, | ||
ComputedRef, | ||
WatchSource, | ||
shallowRef, | ||
computed, | ||
watch, | ||
isRef | ||
} from '@vue/composition-api' | ||
@@ -20,9 +28,9 @@ export type Refish<T = any> = T | Ref<T> | ComputedRef<T> | ||
export function computedOnly<T, S>( | ||
source: Source<S>, | ||
callback: () => T | ||
source: WatchSource<S>, | ||
fn: (value: S, oldValue?: S) => T | ||
): Ref<T> { | ||
const value = ref() as Ref<T> | ||
const value = shallowRef() as Ref<T> | ||
watch(source, () => { | ||
value.value = callback() | ||
watch(source, (newValue, oldValue) => { | ||
value.value = fn(newValue, oldValue) | ||
}, { immediate: true }) | ||
@@ -45,22 +53,12 @@ | ||
export function computedIfOnly<T, R, E>( | ||
refish: Ref<T | null> | ComputedRef<T | null> | (() => T | null), | ||
callback: (value: T) => R, | ||
export function computedIfOnly<T, E, S>( | ||
source: WatchSource<S>, | ||
fn: (value: Exclude<S, undefined | null | false>) => T, | ||
empty: E | ||
): Ref<R | E> { | ||
const value = ref<R | E>(empty) | ||
const refValue = get(refish) | ||
if (refValue) { | ||
value.value = callback(refValue) as UnwrapRef<R> | ||
} | ||
watch(refish, (newValue) => { | ||
value.value = newValue | ||
? callback(newValue) as UnwrapRef<R> | ||
: empty as UnwrapRef<E> | ||
): Ref<T | E> { | ||
return computedOnly(source, (value) => { | ||
return value | ||
? fn(value as Exclude<S, undefined | null | false>) | ||
: empty | ||
}) | ||
return value as Ref<R | E> | ||
} | ||
@@ -67,0 +65,0 @@ |
{ | ||
"name": "@globalbrain/sefirot", | ||
"version": "0.53.0", | ||
"version": "0.53.1", | ||
"description": "Vue Components for Global Brain Design System.", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
295066
1987