From 6e1bfd6ea6781d1ac1046a11fe71b7b2c51952fd Mon Sep 17 00:00:00 2001 From: SIMDD Date: Mon, 6 May 2019 10:54:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20unused=20variabl?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/combo.ts | 11 ----------- src/store/form.ts | 13 ++++++------- src/store/formItem.ts | 25 ++++++++++++------------- src/store/iRenderer.ts | 35 ++++++++++++++++------------------- src/store/list.ts | 3 +-- 5 files changed, 35 insertions(+), 52 deletions(-) diff --git a/src/store/combo.ts b/src/store/combo.ts index 336495300..2c4394c14 100644 --- a/src/store/combo.ts +++ b/src/store/combo.ts @@ -9,21 +9,10 @@ import { import { iRendererStore, } from './iRenderer'; -import { - IRendererStore -} from './index'; import { FormItemStore, IFormItemStore } from './formItem'; -import { - Api, - Payload, - fetchOptions -} from '../types'; -import { - extendObject -} from '../utils/helper'; import {FormStore, IFormStore} from './form'; export const UniqueGroup = types diff --git a/src/store/form.ts b/src/store/form.ts index 508e4ebb9..960162467 100644 --- a/src/store/form.ts +++ b/src/store/form.ts @@ -23,7 +23,6 @@ import { setVariable, deleteVariable, cloneObject, - extendObject, createObject, difference, guid @@ -98,7 +97,7 @@ export const FormStore = ServiceStore function setValues(values:object, tag?:object) { self.updateData(values, tag); - + // 同步 options syncOptions(); } @@ -132,7 +131,7 @@ export const FormStore = ServiceStore writable: false, }); } - + setVariable(data, name, value); self.data = data; @@ -168,7 +167,7 @@ export const FormStore = ServiceStore writable: false, }); } - + deleteVariable(data, name); self.data = data; } @@ -198,7 +197,7 @@ export const FormStore = ServiceStore self.markSaving(true); const json:Payload = yield (getRoot(self) as IRendererStore).fetcher(api, data, options); - + if (!json.ok) { // 验证错误 @@ -243,7 +242,7 @@ export const FormStore = ServiceStore // 已经销毁了,不管这些数据了。 return; } - + self.markSaving(false); // console.error(e.stack);` (getRoot(self) as IRendererStore).notify('error', e.message); @@ -254,7 +253,7 @@ export const FormStore = ServiceStore const submit:(fn?:(values:object) => Promise, hooks?: Array<() => Promise>) => Promise = flow(function *submit(fn:any, hooks?: Array<() => Promise>) { self.submited = true; self.submiting = true; - + try { let valid = yield validate(hooks); diff --git a/src/store/formItem.ts b/src/store/formItem.ts index bcc2894bf..8077dc2be 100644 --- a/src/store/formItem.ts +++ b/src/store/formItem.ts @@ -6,7 +6,6 @@ import { getRoot } from "mobx-state-tree"; import { - FormStore, IFormStore } from './form'; import { @@ -165,10 +164,10 @@ export const FormItemStore = types return []; } - const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item) + const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item) : typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value]; const selectedOptions:Array = []; - + self.filteredOptions.forEach((item:any) => { let idx = findIndex(selected, seleced => { return isObject(seleced) ? seleced === item[self.valueField || 'value'] :String(item[self.valueField || 'value']) === String(seleced) @@ -179,7 +178,7 @@ export const FormItemStore = types selectedOptions.push(item); } }); - + selected.forEach((item, index) => { let unMatched = value && value[index] || item; @@ -189,7 +188,7 @@ export const FormItemStore = types [self.labelField || 'label']: item, } } - + unMatched && selectedOptions.push(unMatched); }); @@ -355,7 +354,7 @@ export const FormItemStore = types let options:Array = json.data.options || json.data.items || json.data.rows || json.data || []; options = normalizeOptions(options as any); setOptions(options); - + if (json.data && typeof (json.data as any).value !== "undefined") { onChange && onChange((json.data as any).value); } else if (clearValue) { @@ -392,26 +391,26 @@ export const FormItemStore = types const form = self.form; const value = self.value; - const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item) + const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item) : typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value]; let filteredOptions = self.options - .filter((item:any) => + .filter((item:any) => item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false : item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true : (item.visible !== false || item.hidden !== true) ) .map((item:any, index) => { - + const disabled = evalExpression(item.disabledOn, form.data); const newItem = item.disabledOn ? ( - self.filteredOptions.length > index && self.filteredOptions[index].disabled === disabled + self.filteredOptions.length > index && self.filteredOptions[index].disabled === disabled ? self.filteredOptions[index] : { ...item, disabled: disabled } - ) + ) : item; return newItem; @@ -419,7 +418,7 @@ export const FormItemStore = types const flattened:Array = flattenTree(filteredOptions); const selectedOptions:Array = []; - + selected.forEach((item, index) => { let idx = findIndex(flattened, target => { return isObject(item) ? item === target[self.valueField || 'value'] : String(target[self.valueField || 'value']) === String(item) @@ -437,7 +436,7 @@ export const FormItemStore = types __unmatched: true } } - + unMatched && selectedOptions.push(unMatched); } }); diff --git a/src/store/iRenderer.ts b/src/store/iRenderer.ts index 96c27a7ef..e8a30b800 100644 --- a/src/store/iRenderer.ts +++ b/src/store/iRenderer.ts @@ -5,13 +5,10 @@ import { SnapshotIn } from "mobx-state-tree"; import { - cloneObject, extendObject, - createObject, - isObjectShallowModified + createObject } from '../utils/helper'; import {IRendererStore} from './index'; -import { Action } from "../types"; import { dataMapping } from "../utils/tpl-builtin"; export const iRendererStore = types @@ -47,11 +44,11 @@ export const iRendererStore = types self.pristine = data; self.data = data; }, - + reset() { self.data = self.pristine; }, - + updateData(data:object = {}, tag?: object) { const prev = self.data; let newData; @@ -64,32 +61,32 @@ export const iRendererStore = types } else { newData = extendObject(self.data, data); } - + Object.defineProperty(newData, '__prev', { value: {...prev}, enumerable: false, configurable: false, writable: false, }); - + self.data = newData; }, - + setCurrentAction(action:object) { self.action = action; }, - + openDialog(ctx: any, additonal?:object, callback?: (ret:any) => void) { let proto = ctx.__super ? ctx.__super : self.data; - + if (additonal) { proto = createObject(proto, additonal); } - + const data = createObject(proto, { ...ctx }); - + if (self.action.dialog && self.action.dialog.data) { self.dialogData = createObject(proto, { ...dataMapping(self.action.dialog.data, data) @@ -103,7 +100,7 @@ export const iRendererStore = types dialogCallbacks.set(self.dialogData, callback); } }, - + closeDialog(result?:any) { const callback = dialogCallbacks.get(self.dialogData); @@ -114,18 +111,18 @@ export const iRendererStore = types setTimeout(() => callback(result), 200); } }, - + openDrawer(ctx: any, additonal?:object, callback?: (ret:any) => void) { let proto = ctx.__super ? ctx.__super : self.data; - + if (additonal) { proto = createObject(proto, additonal); } - + const data = createObject(proto, { ...ctx }); - + if (self.action.drawer.data) { self.drawerData = dataMapping(self.action.drawer.data, data); } else { @@ -137,7 +134,7 @@ export const iRendererStore = types dialogCallbacks.set(self.drawerData, callback); } }, - + closeDrawer(result?:any) { const callback = dialogCallbacks.get(self.drawerData); self.drawerOpen = false; diff --git a/src/store/list.ts b/src/store/list.ts index d80f67c86..1019f404f 100644 --- a/src/store/list.ts +++ b/src/store/list.ts @@ -9,7 +9,6 @@ import { import { iRendererStore, } from './iRenderer'; -import { resolveVariable } from "../utils/tpl-builtin"; import isEqual = require('lodash/isEqual'); import find = require('lodash/find'); import { createObject, isObject } from "../utils/helper"; @@ -171,7 +170,7 @@ export const ListStore = iRendererStore item = isObject(item) ? item : { item: item }; - + return { id: String((item as any)[self.primaryField] || key), index: key,