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+$/ 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; +};