@globalbrain/sefirot
Advanced tools
Comparing version 0.33.0 to 0.34.0
@@ -0,1 +1,11 @@ | ||
# [0.34.0](https://github.com/globalbrain/sefirot/compare/v0.33.0...v0.34.0) (2021-01-28) | ||
### Bug Fixes | ||
* **modal:** not current modals propery ([82c2399](https://github.com/globalbrain/sefirot/commit/82c23990b0985b78cba358dda8aa773a019ee57e)) | ||
### Features | ||
* add computedIfOnly composable utility function ([a8ada61](https://github.com/globalbrain/sefirot/commit/a8ada615c07e4864266027a7409baa9b46043e69)) | ||
# [0.33.0](https://github.com/globalbrain/sefirot/compare/v0.32.1...v0.33.0) (2021-01-27) | ||
@@ -2,0 +12,0 @@ |
@@ -1,11 +0,11 @@ | ||
import { Ref, ComputedRef, computed, isRef } from '@vue/composition-api' | ||
import { Ref, ComputedRef, UnwrapRef, ref, computed, watch, isRef } from '@vue/composition-api' | ||
export type Refish<T = any> = T | Ref<T> | ComputedRef<T> | ||
export function get<T>(ref: Refish<T>): T { | ||
return isRef(ref) ? ref.value : ref | ||
export function get<T>(refish: Refish<T>): T { | ||
return isRef(refish) ? refish.value : refish | ||
} | ||
export function computedIf<T, R, E>( | ||
ref: Refish<T | null>, | ||
refish: Refish<T | null>, | ||
callback: (value: T) => R, | ||
@@ -15,3 +15,3 @@ empty: E | ||
return computed(() => { | ||
const value = get(ref) | ||
const value = get(refish) | ||
@@ -22,4 +22,20 @@ return value ? callback(value) : empty | ||
export function computedIfOnly<T, R, E>( | ||
refish: Ref<T | null> | ComputedRef<T | null>, | ||
callback: (value: T) => R, | ||
empty: E | ||
): Ref<R | E> { | ||
const value = ref<R | E>(empty) | ||
watch(refish, (newValue) => { | ||
value.value = newValue | ||
? callback(newValue) as UnwrapRef<R> | ||
: empty as UnwrapRef<E> | ||
}) | ||
return value as Ref<R | E> | ||
} | ||
export function computedArrayIf<T, D extends any[]>( | ||
ref: Refish<T | null>, | ||
refish: Refish<T | null>, | ||
callback: (carry: D, value: T) => void | ||
@@ -30,3 +46,3 @@ ): ComputedRef<D> { | ||
const value = get(ref) | ||
const value = get(refish) | ||
@@ -33,0 +49,0 @@ value && callback(carry, value) |
@@ -72,5 +72,6 @@ import { GetterTree, ActionTree, ActionContext, MutationTree } from 'vuex' | ||
back(state: State): void { | ||
const latestItem = state.history[state.history.length - 2] | ||
const latestIndex = state.history.findIndex(h => h.name === state.name) | ||
const previousItem = state.history[latestIndex - 1] | ||
state.name = latestItem ? latestItem.name : null | ||
state.name = previousItem ? previousItem.name : null | ||
}, | ||
@@ -77,0 +78,0 @@ |
{ | ||
"name": "@globalbrain/sefirot", | ||
"version": "0.33.0", | ||
"version": "0.34.0", | ||
"description": "Vue Components for Global Brain Design System.", | ||
@@ -5,0 +5,0 @@ "files": [ |
238616
1602