[Improvement] optimize utils (#661)

This commit is contained in:
neverland 2018-03-02 14:39:26 +08:00 committed by GitHub
parent 39cdaf0907
commit 92b116c071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 22 deletions

View File

@ -128,10 +128,6 @@ module.exports = {
path: '/progress',
title: 'Progress - 进度条'
},
{
path: '/search',
title: 'Search - 搜索'
},
{
path: '/stepper',
title: 'Stepper - 步进器'
@ -185,6 +181,10 @@ module.exports = {
path: '/radio',
title: 'Radio - 单选框'
},
{
path: '/search',
title: 'Search - 搜索'
},
{
path: '/switch',
title: 'Switch - 开关'
@ -414,10 +414,6 @@ module.exports = {
path: '/progress',
title: 'Progress'
},
{
path: '/search',
title: 'Search'
},
{
path: '/stepper',
title: 'Stepper'
@ -471,6 +467,10 @@ module.exports = {
path: '/radio',
title: 'Radio'
},
{
path: '/search',
title: 'Search'
},
{
path: '/switch',
title: 'Switch'

View File

@ -16,7 +16,7 @@
</template>
<script>
import { create } from '../utils';
import { create, isObj } from '../utils';
import Picker from '../picker';
export default create({
@ -42,7 +42,7 @@ export default create({
computed: {
listValid() {
return this.areaList && typeof this.areaList.province_list === 'object';
return this.areaList && isObj(this.areaList.province_list);
},
columns() {

View File

@ -25,7 +25,7 @@
</template>
<script>
import { create } from '../utils';
import { create, isObj } from '../utils';
const DEFAULT_DURATION = 200;
const range = (num, arr) => Math.min(Math.max(num, arr[0]), arr[1]);
@ -147,11 +147,11 @@ export default create({
},
isDisabled(option) {
return typeof option === 'object' && option.disabled;
return isObj(option) && option.disabled;
},
getOptionText(option) {
return typeof option === 'object' && this.valueKey in option ? option[this.valueKey] : option;
return isObj(option) && this.valueKey in option ? option[this.valueKey] : option;
},
setIndex(index, userAction) {

View File

@ -1,5 +1,6 @@
import Vue from 'vue';
import VueToast from './toast';
import { isObj } from '../utils';
const defaultOptions = {
type: 'text',
@ -10,7 +11,7 @@ const defaultOptions = {
position: 'middle',
forbidClick: false
};
const parseOptions = message => typeof message === 'object' ? message : { message };
const parseOptions = message => isObj(message) ? message : { message };
let queue = [];
let singleton = true;

View File

@ -8,10 +8,10 @@ import install from './install';
import Loading from '../loading';
export default function(sfc) {
sfc.mixins = sfc.mixins || [];
sfc.components = sfc.components || {};
sfc.install = sfc.install || install;
sfc.mixins = sfc.mixins || [];
sfc.mixins.push(i18n);
sfc.components = sfc.components || {};
sfc.components.icon = Icon;
sfc.components.loading = Loading;

View File

@ -1,12 +1,7 @@
import { isDef } from './';
import { isDef, isObj } from './';
const { hasOwnProperty } = Object.prototype;
function isObj(x) {
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
function assignKey(to, from, key) {
const val = from[key];

View File

@ -7,6 +7,11 @@ function isDef(value) {
return value !== undefined && value !== null;
}
function isObj(x) {
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
function get(object, path) {
const keys = path.split('.');
let result = object;
@ -30,6 +35,7 @@ function isAndroid() {
export {
get,
isObj,
isDef,
create,
isServer,