jenesius-vue-form
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -9,3 +9,9 @@ import { Values } from "../types"; | ||
static EVENT_DEPEND: string; | ||
static EVENT_READ: string; | ||
static EVENT_SAVE: string; | ||
static getParentForm(): Form; | ||
/** | ||
* Version of current form. Can be used for check the current data of form. | ||
* */ | ||
version: number | undefined; | ||
name?: string; | ||
@@ -76,3 +82,20 @@ /** | ||
private setHiddenFields; | ||
/** | ||
* @description Function for read data (For example from DataBase) | ||
* */ | ||
private readData; | ||
/** | ||
* @description Method takes read functions from all children elements, and | ||
* run it | ||
*/ | ||
get read(): FunctionHandleData; | ||
set read(callback: FunctionHandleData); | ||
/** | ||
* @description Function for save data (Update/Create) | ||
* */ | ||
private saveData; | ||
get save(): FunctionHandleData; | ||
set save(callback: FunctionHandleData); | ||
} | ||
declare type FunctionHandleData = () => Promise<any> | any | void; | ||
export interface FormParams { | ||
@@ -86,1 +109,2 @@ name?: string; | ||
} | ||
export {}; |
/*! | ||
* jenesius-vue-form v1.0.12 | ||
* jenesius-vue-form v1.0.13 | ||
* (c) 2022 Jenesius | ||
@@ -101,2 +101,6 @@ * @license MIT | ||
function runPromiseQueue(guards) { | ||
return guards.reduce((promiseAccumulator, fn) => promiseAccumulator.then((x) => fn === null || fn === void 0 ? void 0 : fn(x)), Promise.resolve()); | ||
} | ||
class Form extends EventEmitter__default["default"] { | ||
@@ -106,2 +110,6 @@ constructor(params) { | ||
/** | ||
* Version of current form. Can be used for check the current data of form. | ||
* */ | ||
this.version = undefined; | ||
/** | ||
* @description ComputedRef, true - when one of form's elements is changed. | ||
@@ -125,2 +133,10 @@ * */ | ||
this.hiddenFields = vue.reactive([]); | ||
/** | ||
* @description Function for read data (For example from DataBase) | ||
* */ | ||
this.readData = () => Promise.resolve(); | ||
/** | ||
* @description Function for save data (Update/Create) | ||
* */ | ||
this.saveData = () => Promise.resolve(); | ||
if (params.name) | ||
@@ -367,2 +383,35 @@ this.name = params.name; | ||
} | ||
/** | ||
* @description Method takes read functions from all children elements, and | ||
* run it | ||
*/ | ||
get read() { | ||
const array = this.dependElements.reduce((acc, elemController) => { | ||
if (elemController.read) | ||
acc.push(elemController.read); | ||
return acc; | ||
}, []); | ||
if (this.readData) | ||
array.push(() => runPromiseQueue([() => { var _a; return (_a = this.readData) === null || _a === void 0 ? void 0 : _a.call(this); }, (data) => this.emit(Form.EVENT_READ, data)])); | ||
return () => Promise.all(array.map(c => c())); | ||
} | ||
set read(callback) { | ||
this.readData = callback; | ||
} | ||
get save() { | ||
const array = this.dependElements.reduce((acc, elemController) => { | ||
if (elemController.save) | ||
acc.push(elemController.save); | ||
return acc; | ||
}, []); | ||
array.push(() => runPromiseQueue([ | ||
() => { var _a; return (_a = this.saveData) === null || _a === void 0 ? void 0 : _a.call(this); }, | ||
(data) => this.emit(Form.EVENT_SAVE, data), | ||
() => this.cleanChanges() | ||
])); | ||
return () => Promise.all(array.map(c => c())); | ||
} | ||
set save(callback) { | ||
this.saveData = callback; | ||
} | ||
} | ||
@@ -374,2 +423,4 @@ Form.PROVIDE_NAME = 'form-controller'; | ||
Form.EVENT_DEPEND = 'on-depend'; | ||
Form.EVENT_READ = 'read'; | ||
Form.EVENT_SAVE = 'save'; | ||
@@ -376,0 +427,0 @@ class Input extends EventEmitter__default["default"] { |
{ | ||
"name": "jenesius-vue-form", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "email": "lokargenia@gmail.com", |
28901
18
748