@globalbrain/sefirot
Advanced tools
Comparing version 0.32.1 to 0.33.0
@@ -0,1 +1,7 @@ | ||
# [0.33.0](https://github.com/globalbrain/sefirot/compare/v0.32.1...v0.33.0) (2021-01-27) | ||
### Features | ||
* **form:** add callback data creation support in useData composable ([0622618](https://github.com/globalbrain/sefirot/commit/0622618af60646041a1cafb027ac68370c3c3b61)) | ||
## [0.32.1](https://github.com/globalbrain/sefirot/compare/v0.32.0...v0.32.1) (2021-01-26) | ||
@@ -2,0 +8,0 @@ |
@@ -5,2 +5,3 @@ import { reactive } from '@vue/composition-api' | ||
data: T | ||
init: InitFunction | ||
update: UpdateFunction | ||
@@ -10,7 +11,12 @@ } | ||
export type State = Record<string, any> | ||
export type InitFunction = () => void | ||
export type UpdateFunction = (model: string, value: any) => void | ||
export function useFormData<T extends State>(data: T): Data<T> { | ||
const state = reactive(data) | ||
export function useFormData<T extends State>(data: T | (() => T)): Data<T> { | ||
const state = reactive(getData(data)) | ||
function init(): void { | ||
initData(state, getData(data) as any) | ||
} | ||
function update(model: string, value: any): void { | ||
@@ -22,2 +28,3 @@ updateData(state, model, value) | ||
data: state as T, | ||
init, | ||
update | ||
@@ -27,4 +34,12 @@ } | ||
function getData<T extends State>(data: T | (() => T)): T { | ||
return data instanceof Function ? data() : data | ||
} | ||
function initData<T extends State>(data: T, source: T): void { | ||
Object.assign(data, source) | ||
} | ||
function updateData<T extends State>(data: T, model: string, value: any): void { | ||
(data as any)[model] = value | ||
} |
{ | ||
"name": "@globalbrain/sefirot", | ||
"version": "0.32.1", | ||
"version": "0.33.0", | ||
"description": "Vue Components for Global Brain Design System.", | ||
@@ -5,0 +5,0 @@ "files": [ |
237734
1588