mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 06:31:20 -08:00
简化工具函数
This commit is contained in:
1 parent
be4d1d0437
commit
1270167a3e
26 files changed
+182
-152
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { hasClass, addClass, removeClass, append, setStyle, setStyles, tooltip } from './dom';
|
||||
import { hasOwnProperty, defineProperty } from './property';
|
||||
import { has, def } from './property';
|
||||
import { errorHandle } from './error';
|
||||
|
||||
export default class Component {
|
||||
@@ -35,7 +35,7 @@ export default class Component {
|
||||
if (!this.$parent || option.disable) return {};
|
||||
this.id += 1;
|
||||
const name = option.name || `${this.name}${this.id}`;
|
||||
errorHandle(!hasOwnProperty(this, name), `Cannot add a component that already has the same name: ${name}`);
|
||||
errorHandle(!has(this, name), `Cannot add a component that already has the same name: ${name}`);
|
||||
const $ref = document.createElement('div');
|
||||
$ref.classList.value = `art-${this.name} art-${this.name}-${name}`;
|
||||
|
||||
@@ -75,7 +75,7 @@ export default class Component {
|
||||
callback($ref, this, this.art);
|
||||
}
|
||||
|
||||
defineProperty(this, name, {
|
||||
def(this, name, {
|
||||
value: {
|
||||
get $ref() {
|
||||
return $ref;
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import { errorHandle } from './error';
|
||||
|
||||
const has = Object.prototype.hasOwnProperty;
|
||||
export function hasOwnProperty(obj, name) {
|
||||
return has.call(obj, name);
|
||||
}
|
||||
export const def = Object.defineProperty;
|
||||
|
||||
const def = Object.defineProperty;
|
||||
export function defineProperty(obj, key, prop) {
|
||||
return def(obj, key, prop);
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
export function has(obj, name) {
|
||||
return hasOwnProperty.call(obj, name);
|
||||
}
|
||||
|
||||
export function proxyPropertys(target, ...sources) {
|
||||
return sources.reduce((result, source) => {
|
||||
Object.getOwnPropertyNames(source).forEach(key => {
|
||||
errorHandle(!hasOwnProperty(result, key), `Target attribute name is duplicated: ${key}`);
|
||||
errorHandle(!has(result, key), `Target attribute name is duplicated: ${key}`);
|
||||
def(result, key, Object.getOwnPropertyDescriptor(source, key));
|
||||
});
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user