Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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+$/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 0 additions & 38 deletions src/Pluggable/index.js

This file was deleted.

70 changes: 70 additions & 0 deletions src/Pluggable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {Component} from 'react';
import {h} from '../util';

export interface IPluggableOptions<TPluginProps> {
beforePlugins: TPluginProps[],
afterPlugins: TPluginProps[],
render: (state) => React.ReactElement<any>,
}

const createPluggable = <TPluginProps extends {[s: string]: (self, state) => any}>(options: IPluggableOptions<TPluginProps>) => {
const {beforePlugins, afterPlugins, render} = options;


interface IPluggableProps {
plugins?: TPluginProps[],
}

interface IPluggableState {
exec: (name: keyof TPluginProps) => any,
plugins: TPluginProps[],
}

const Pluggable = class Pluggable extends Component<IPluggableProps & TPluginProps, IPluggableState> {
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;
};