From 921ba817ea86cd1acb64904c2392bc0a214c8697 Mon Sep 17 00:00:00 2001 From: Va Da Date: Fri, 25 May 2018 17:49:43 +0100 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20improve=20=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/Pluggable/index.js | 38 ----------------------- src/Pluggable/index.ts | 70 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 39 deletions(-) delete mode 100644 src/Pluggable/index.js create mode 100644 src/Pluggable/index.ts diff --git a/package.json b/package.json index 3a1c0e80..0738bad2 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "jest-environment-jsdom-global": "^1.0.3", "jest-tap-reporter": "1.9.0", "mocha": "5.0.0", - "mol-conventional-changelog": "1.2.0", + "mol-conventional-changelog": "^1.3.0", "react-markdown": "3.1.4", "react-test-renderer": "16.2.0", "rimraf": "2.6.2", diff --git a/src/Pluggable/index.js b/src/Pluggable/index.js deleted file mode 100644 index 0dba93d8..00000000 --- a/src/Pluggable/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import {Component} from 'react'; -import {h} from '../util'; - -export class Pluggable extends Component { - plugins = []; - - constructor (props, context) { - super(props, context); - } - - exec = (name) => { - const {plugins} = this.props; - let result; - let method = this.props[name]; - - if (method) { - - } - - for (let i = 0; i < plugins.length; i++) { - method = plugins[i][name]; - - if (!method) { - continue; - } - - result = method(this); - - if (result !== undefined) { - return result; - } - } - }; - - render () { - - } -} diff --git a/src/Pluggable/index.ts b/src/Pluggable/index.ts new file mode 100644 index 00000000..c2149ed6 --- /dev/null +++ b/src/Pluggable/index.ts @@ -0,0 +1,70 @@ +import {Component} from 'react'; +import {h} from '../util'; + +export interface IPluggableOptions { + beforePlugins: TPluginProps[], + afterPlugins: TPluginProps[], + render: (state) => React.ReactElement, +} + +const createPluggable = any}>(options: IPluggableOptions) => { + const {beforePlugins, afterPlugins, render} = options; + + + interface IPluggableProps { + plugins?: TPluginProps[], + } + + interface IPluggableState { + exec: (name: keyof TPluginProps) => any, + plugins: TPluginProps[], + } + + const Pluggable = class Pluggable extends Component { + state: IPluggableState; + + constructor (props) { + super(props); + + this.state = { + exec: this.exec, + plugins: this.createPluginArray(), + }; + } + + createPluginArray (): TPluginProps[] { + return [ + ...options.beforePlugins, + ...this.props.plugins, + this.props as any as TPluginProps, + ...options.afterPlugins + ]; + } + + exec = (name: keyof TPluginProps) => { + const {plugins} = this.state; + + let result; + + for (let i = 0; i < plugins.length; i++) { + const method = plugins[i][name]; + + if (!method) { + continue; + } + + result = method(this, this.state); + + if (result !== undefined) { + return result; + } + } + }; + + render () { + return render(this.state); + } + }; + + return Pluggable; +}; From 48e536861b58283673d975448a1554e2a0d16b69 Mon Sep 17 00:00:00 2001 From: Va Da Date: Fri, 25 May 2018 17:51:53 +0100 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20=F0=9F=A4=96=20add=20CI=20scripts=20t?= =?UTF-8?q?o=20Travis=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e82bed0e..cec984ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,9 @@ matrix: allow_failures: [] fast_finish: true after_success: - - npm run semantic-release + - npx ci-scripts slack + - npx ci-scripts github-post + - npx semantic-release branches: except: - /^v\d+\.\d+\.\d+$/