From d5d16ed709cab2db049b75298d052c0c589b9f13 Mon Sep 17 00:00:00 2001 From: Harvey Zack Date: Thu, 11 Oct 2018 17:11:55 +0800 Subject: [PATCH] add plugin --- .eslintrc | 2 +- src/index.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 21c5e55df..b0cccffd0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -205,7 +205,7 @@ "no-var": 1, "prefer-const": 1, "prefer-destructuring": 1, - "prefer-spread": 1, + "prefer-spread": 0, "prefer-template": 1, "require-yield": 2, "rest-spread-spacing": 1, diff --git a/src/index.js b/src/index.js index fa48e3f5c..f00465e0e 100644 --- a/src/index.js +++ b/src/index.js @@ -70,6 +70,19 @@ class Artplayer extends Emitter { }; } + static use(plugin) { + const installedPlugins = this.plugins || (this.plugins = []); + if (installedPlugins.indexOf(plugin) > -1) { + return this; + } + + const args = Array.from(arguments).slice(1); + args.unshift(this); + plugin.apply(null, args); + installedPlugins.push(plugin); + return this; + } + init() { this.refs = { container: this.option.container