优化回调参数

This commit is contained in:
Harvey Zack committed 2019-04-22 13:32:27 +08:00
1 parent 2385128abb
commit 62c05ef659
5 files changed
+44 -31

No files matched your search

+17 -1
View File
@@ -1,4 +1,20 @@
import validElement from './validElement';
import { ArtPlayerError } from '../utils';
function validElement(paths, value, type) {
if (type === 'string') {
if (value.trim() === '') {
throw new ArtPlayerError(`${paths.join('.')} can not be empty`);
} else {
return true;
}
}
if (value instanceof Element) {
return true;
}
throw new ArtPlayerError(`${paths.join('.')} require 'string' or 'Element' type, but got '${type}'`);
}
export default {
container: {
@@ -1,17 +0,0 @@
import { ArtPlayerError } from '../utils';
export default function validElement(paths, value, type) {
if (type === 'string') {
if (value.trim() === '') {
throw new ArtPlayerError(`${paths.join('.')} can not be empty`);
} else {
return true;
}
}
if (value instanceof Element) {
return true;
}
throw new ArtPlayerError(`${paths.join('.')} require 'string' or 'Element' type, but got '${type}'`);
}
+13 -6
View File
@@ -1,4 +1,4 @@
import { append, insertByIndex, setStyles, setStyle } from './index';
import { append, insertByIndex, setStyles, setStyle, remove } from './index';
export default function component(art, parent, target, component, callback, title) {
const option = typeof component === 'function' ? component(art) : component;
@@ -19,7 +19,7 @@ export default function component(art, parent, target, component, callback, titl
if (option.click) {
art.events.proxy($element, 'click', event => {
event.preventDefault();
option.click.call(parent, event);
option.click.call(parent, event, art);
art.emit(`${title}:click`, $element);
});
}
@@ -36,20 +36,27 @@ export default function component(art, parent, target, component, callback, titl
});
Object.defineProperty(option, 'show', {
value: () => {
setStyle($element, 'display', 'block');
value: (type = 'block') => {
setStyle($element, 'display', type);
art.emit(`${title}:show`, $element);
},
});
Object.defineProperty(option, 'remove', {
value: () => {
remove($element);
art.emit(`${title}:remove`, $element);
},
});
insertByIndex(target, $element, option.index || parent.id);
if (option.mounted) {
option.mounted($element);
option.mounted($element, parent, art);
}
if (callback) {
callback($element);
callback($element, parent, art);
}
parent[name] = option;