Stable Version with reducers and actions

This commit is contained in:
Belen Curcio
2017-03-29 14:45:59 -03:00
parent 2513ef2df5
commit 520392829b
19 changed files with 75 additions and 71 deletions
+11
View File
@@ -0,0 +1,11 @@
import * as authActions from './auth';
import * as assetActions from './asset';
import * as notificationActions from './notification';
import {actionsImporter} from '../helpers/importer';
export default {
authActions,
assetActions,
notificationActions,
pluginActions: actionsImporter
};
+2 -2
View File
@@ -1,5 +1,5 @@
import React, {Component} from 'react';
import injectedPlugins from 'coral-framework/helpers/importer';
import { importer as injectPlugins } from 'coral-framework/helpers/importer';
class Slot extends Component {
componentDidMount() {
@@ -9,7 +9,7 @@ class Slot extends Component {
const {fill} = this.props;
return (
<div>
{injectedPlugins(fill)}
{injectPlugins(fill)}
</div>
);
}
+43 -15
View File
@@ -19,20 +19,6 @@ function importer (fill) {
.map(key => shapeData(key));
}
function shapeData(test) {
/**
* shapeData shapes each item in the plugins array with useful data
* returns an Object with the name of the plugin, the format, and it's key(filename)
*/
const match = test.match(/\.\/(.*)\/client\/.*.(json|js)$/);
return {
name: match[1],
format: match[2],
key: match[0]
};
}
function getConfig (name) {
/**
@@ -85,5 +71,47 @@ function importer (fill) {
return init();
}
export default importer;
function shapeData(test) {
/**
* shapeData shapes each item in the plugins array with useful data
* returns an Object with the name of the plugin, the format, and it's key(filename)
*/
const match = test.match(/\.\/(.*)\/client\/.*.(json|js)$/);
return {
name: match[1],
format: match[2],
key: match[0]
};
}
function actionsImporter () {
const context = require.context('plugins', true, /\.\/(.*)\/client\/actions.js$/);
return context
.keys()
.map(key => shapeData(key))
.reduce((entry, actionsPlugin, i) => {
entry[actionsPlugin.name] = context(actionsPlugin.key);
return entry;
}, {});
}
function reducersImporter () {
const context = require.context('plugins', true, /\.\/(.*)\/client\/reducer.js$/);
return context
.keys()
.map(key => shapeData(key))
.reduce((entry, reducerPlugin, i) => {
entry[reducerPlugin.name] = context(reducerPlugin.key);
return entry;
}, {});
}
export default {
importer,
actionsImporter: actionsImporter(),
reducersImporter: reducersImporter()
};
+4 -13
View File
@@ -1,23 +1,14 @@
import store from './services/store';
import pym from './services/PymConnection';
import I18n from './modules/i18n/i18n';
import * as authActions from './actions/auth';
import * as assetActions from './actions/asset';
import * as notificationActions from './actions/notification';
import actions from './actions';
import Slot from './components/Slot';
const context = require.context('plugins', true, /\.\/(.*)\/client\/actions.js$/);
const pluginsActions = context
.keys()
.reduce(entry, key => entry[key] = context(key), {});
export {
console.log(actions)
export default {
pym,
Slot,
I18n,
store,
authActions,
assetActions,
notificationActions,
pluginsActions
...actions
};
+2
View File
@@ -1,9 +1,11 @@
import auth from './auth';
import user from './user';
import asset from './asset';
import {reducersImporter} from '../helpers/importer';
export default {
auth,
user,
asset,
...reducersImporter
};
@@ -1,4 +0,0 @@
{
"name": "Coral Plugin Love",
"slot": "Comment.InfoBar"
}
@@ -1,8 +0,0 @@
import React from 'react';
import styles from './style.css';
export default (props) => (
<div className={styles.Love}>
<button>Love</button>
</div>
);
@@ -1,9 +0,0 @@
.Love {
display: inline-block;
button {
padding: 10px 2px;
border-radius: 3px;
background: deepskyblue;
color: #161616;
}
}
View File
@@ -1,4 +0,0 @@
{
"name": "Coral Plugin Tab Monitor",
"slot": "Stream"
}
@@ -1,12 +0,0 @@
import React from 'react';
import {TabBar, Tab} from 'coral-ui';
console.log('exported');
export default (props) => (
<TabBar>
<Tab>
Monitor
</Tab>
</TabBar>
);
@@ -0,0 +1 @@
export const clickButton = () => ({type: 'BUTTON_CLICKED'});
@@ -0,0 +1,12 @@
import {Map} from 'immutable';
const initialState = Map({
clicked: false
});
export default function reducer (state = initialState, action) {
switch (action.type) {
default:
return state;
}
}
@@ -1 +0,0 @@
export const SomeAction = () => ({type: 'SomeAction'});
@@ -1,3 +0,0 @@
{
"name": "Coral Plugin"
}