Merge pull request #14 from simdd/master

fix: remove unused variable
This commit is contained in:
liaoxuezhi 2019-05-06 10:59:58 +08:00 committed by GitHub
commit e64f80a947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 52 deletions

View File

@ -9,21 +9,10 @@ import {
import { import {
iRendererStore, iRendererStore,
} from './iRenderer'; } from './iRenderer';
import {
IRendererStore
} from './index';
import { import {
FormItemStore, FormItemStore,
IFormItemStore IFormItemStore
} from './formItem'; } from './formItem';
import {
Api,
Payload,
fetchOptions
} from '../types';
import {
extendObject
} from '../utils/helper';
import {FormStore, IFormStore} from './form'; import {FormStore, IFormStore} from './form';
export const UniqueGroup = types export const UniqueGroup = types

View File

@ -23,7 +23,6 @@ import {
setVariable, setVariable,
deleteVariable, deleteVariable,
cloneObject, cloneObject,
extendObject,
createObject, createObject,
difference, difference,
guid guid
@ -98,7 +97,7 @@ export const FormStore = ServiceStore
function setValues(values:object, tag?:object) { function setValues(values:object, tag?:object) {
self.updateData(values, tag); self.updateData(values, tag);
// 同步 options // 同步 options
syncOptions(); syncOptions();
} }
@ -132,7 +131,7 @@ export const FormStore = ServiceStore
writable: false, writable: false,
}); });
} }
setVariable(data, name, value); setVariable(data, name, value);
self.data = data; self.data = data;
@ -168,7 +167,7 @@ export const FormStore = ServiceStore
writable: false, writable: false,
}); });
} }
deleteVariable(data, name); deleteVariable(data, name);
self.data = data; self.data = data;
} }
@ -198,7 +197,7 @@ export const FormStore = ServiceStore
self.markSaving(true); self.markSaving(true);
const json:Payload = yield (getRoot(self) as IRendererStore).fetcher(api, data, options); const json:Payload = yield (getRoot(self) as IRendererStore).fetcher(api, data, options);
if (!json.ok) { if (!json.ok) {
// 验证错误 // 验证错误
@ -243,7 +242,7 @@ export const FormStore = ServiceStore
// 已经销毁了,不管这些数据了。 // 已经销毁了,不管这些数据了。
return; return;
} }
self.markSaving(false); self.markSaving(false);
// console.error(e.stack);` // console.error(e.stack);`
(getRoot(self) as IRendererStore).notify('error', e.message); (getRoot(self) as IRendererStore).notify('error', e.message);
@ -254,7 +253,7 @@ export const FormStore = ServiceStore
const submit:(fn?:(values:object) => Promise<any>, hooks?: Array<() => Promise<any>>) => Promise<any> = flow(function *submit(fn:any, hooks?: Array<() => Promise<any>>) { const submit:(fn?:(values:object) => Promise<any>, hooks?: Array<() => Promise<any>>) => Promise<any> = flow(function *submit(fn:any, hooks?: Array<() => Promise<any>>) {
self.submited = true; self.submited = true;
self.submiting = true; self.submiting = true;
try { try {
let valid = yield validate(hooks); let valid = yield validate(hooks);

View File

@ -6,7 +6,6 @@ import {
getRoot getRoot
} from "mobx-state-tree"; } from "mobx-state-tree";
import { import {
FormStore,
IFormStore IFormStore
} from './form'; } from './form';
import { import {
@ -165,10 +164,10 @@ export const FormItemStore = types
return []; 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]; : typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value];
const selectedOptions:Array<any> = []; const selectedOptions:Array<any> = [];
self.filteredOptions.forEach((item:any) => { self.filteredOptions.forEach((item:any) => {
let idx = findIndex(selected, seleced => { let idx = findIndex(selected, seleced => {
return isObject(seleced) ? seleced === item[self.valueField || 'value'] :String(item[self.valueField || 'value']) === String(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); selectedOptions.push(item);
} }
}); });
selected.forEach((item, index) => { selected.forEach((item, index) => {
let unMatched = value && value[index] || item; let unMatched = value && value[index] || item;
@ -189,7 +188,7 @@ export const FormItemStore = types
[self.labelField || 'label']: item, [self.labelField || 'label']: item,
} }
} }
unMatched && selectedOptions.push(unMatched); unMatched && selectedOptions.push(unMatched);
}); });
@ -355,7 +354,7 @@ export const FormItemStore = types
let options:Array<IOption> = json.data.options || json.data.items || json.data.rows || json.data || []; let options:Array<IOption> = json.data.options || json.data.items || json.data.rows || json.data || [];
options = normalizeOptions(options as any); options = normalizeOptions(options as any);
setOptions(options); setOptions(options);
if (json.data && typeof (json.data as any).value !== "undefined") { if (json.data && typeof (json.data as any).value !== "undefined") {
onChange && onChange((json.data as any).value); onChange && onChange((json.data as any).value);
} else if (clearValue) { } else if (clearValue) {
@ -392,26 +391,26 @@ export const FormItemStore = types
const form = self.form; const form = self.form;
const value = self.value; 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]; : typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value];
let filteredOptions = self.options let filteredOptions = self.options
.filter((item:any) => .filter((item:any) =>
item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false
: item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true : item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true
: (item.visible !== false || item.hidden !== true) : (item.visible !== false || item.hidden !== true)
) )
.map((item:any, index) => { .map((item:any, index) => {
const disabled = evalExpression(item.disabledOn, form.data); const disabled = evalExpression(item.disabledOn, form.data);
const newItem = item.disabledOn 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] ? self.filteredOptions[index]
: { : {
...item, ...item,
disabled: disabled disabled: disabled
} }
) )
: item; : item;
return newItem; return newItem;
@ -419,7 +418,7 @@ export const FormItemStore = types
const flattened:Array<any> = flattenTree(filteredOptions); const flattened:Array<any> = flattenTree(filteredOptions);
const selectedOptions:Array<any> = []; const selectedOptions:Array<any> = [];
selected.forEach((item, index) => { selected.forEach((item, index) => {
let idx = findIndex(flattened, target => { let idx = findIndex(flattened, target => {
return isObject(item) ? item === target[self.valueField || 'value'] : String(target[self.valueField || 'value']) === String(item) 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: true
} }
} }
unMatched && selectedOptions.push(unMatched); unMatched && selectedOptions.push(unMatched);
} }
}); });

View File

@ -5,13 +5,10 @@ import {
SnapshotIn SnapshotIn
} from "mobx-state-tree"; } from "mobx-state-tree";
import { import {
cloneObject,
extendObject, extendObject,
createObject, createObject
isObjectShallowModified
} from '../utils/helper'; } from '../utils/helper';
import {IRendererStore} from './index'; import {IRendererStore} from './index';
import { Action } from "../types";
import { dataMapping } from "../utils/tpl-builtin"; import { dataMapping } from "../utils/tpl-builtin";
export const iRendererStore = types export const iRendererStore = types
@ -47,11 +44,11 @@ export const iRendererStore = types
self.pristine = data; self.pristine = data;
self.data = data; self.data = data;
}, },
reset() { reset() {
self.data = self.pristine; self.data = self.pristine;
}, },
updateData(data:object = {}, tag?: object) { updateData(data:object = {}, tag?: object) {
const prev = self.data; const prev = self.data;
let newData; let newData;
@ -64,32 +61,32 @@ export const iRendererStore = types
} else { } else {
newData = extendObject(self.data, data); newData = extendObject(self.data, data);
} }
Object.defineProperty(newData, '__prev', { Object.defineProperty(newData, '__prev', {
value: {...prev}, value: {...prev},
enumerable: false, enumerable: false,
configurable: false, configurable: false,
writable: false, writable: false,
}); });
self.data = newData; self.data = newData;
}, },
setCurrentAction(action:object) { setCurrentAction(action:object) {
self.action = action; self.action = action;
}, },
openDialog(ctx: any, additonal?:object, callback?: (ret:any) => void) { openDialog(ctx: any, additonal?:object, callback?: (ret:any) => void) {
let proto = ctx.__super ? ctx.__super : self.data; let proto = ctx.__super ? ctx.__super : self.data;
if (additonal) { if (additonal) {
proto = createObject(proto, additonal); proto = createObject(proto, additonal);
} }
const data = createObject(proto, { const data = createObject(proto, {
...ctx ...ctx
}); });
if (self.action.dialog && self.action.dialog.data) { if (self.action.dialog && self.action.dialog.data) {
self.dialogData = createObject(proto, { self.dialogData = createObject(proto, {
...dataMapping(self.action.dialog.data, data) ...dataMapping(self.action.dialog.data, data)
@ -103,7 +100,7 @@ export const iRendererStore = types
dialogCallbacks.set(self.dialogData, callback); dialogCallbacks.set(self.dialogData, callback);
} }
}, },
closeDialog(result?:any) { closeDialog(result?:any) {
const callback = dialogCallbacks.get(self.dialogData); const callback = dialogCallbacks.get(self.dialogData);
@ -114,18 +111,18 @@ export const iRendererStore = types
setTimeout(() => callback(result), 200); setTimeout(() => callback(result), 200);
} }
}, },
openDrawer(ctx: any, additonal?:object, callback?: (ret:any) => void) { openDrawer(ctx: any, additonal?:object, callback?: (ret:any) => void) {
let proto = ctx.__super ? ctx.__super : self.data; let proto = ctx.__super ? ctx.__super : self.data;
if (additonal) { if (additonal) {
proto = createObject(proto, additonal); proto = createObject(proto, additonal);
} }
const data = createObject(proto, { const data = createObject(proto, {
...ctx ...ctx
}); });
if (self.action.drawer.data) { if (self.action.drawer.data) {
self.drawerData = dataMapping(self.action.drawer.data, data); self.drawerData = dataMapping(self.action.drawer.data, data);
} else { } else {
@ -137,7 +134,7 @@ export const iRendererStore = types
dialogCallbacks.set(self.drawerData, callback); dialogCallbacks.set(self.drawerData, callback);
} }
}, },
closeDrawer(result?:any) { closeDrawer(result?:any) {
const callback = dialogCallbacks.get(self.drawerData); const callback = dialogCallbacks.get(self.drawerData);
self.drawerOpen = false; self.drawerOpen = false;

View File

@ -9,7 +9,6 @@ import {
import { import {
iRendererStore, iRendererStore,
} from './iRenderer'; } from './iRenderer';
import { resolveVariable } from "../utils/tpl-builtin";
import isEqual = require('lodash/isEqual'); import isEqual = require('lodash/isEqual');
import find = require('lodash/find'); import find = require('lodash/find');
import { createObject, isObject } from "../utils/helper"; import { createObject, isObject } from "../utils/helper";
@ -171,7 +170,7 @@ export const ListStore = iRendererStore
item = isObject(item) ? item : { item = isObject(item) ? item : {
item: item item: item
}; };
return { return {
id: String((item as any)[self.primaryField] || key), id: String((item as any)[self.primaryField] || key),
index: key, index: key,