mirror of
https://github.com/wassname/talk.git
synced 2026-07-01 03:43:48 +08:00
Plugins: Reducers and Actions - Working
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, {Component} from 'react';
|
||||
import {importer as injectPlugins} from 'coral-framework/helpers/importer';
|
||||
import actions from 'coral-framework/actions';
|
||||
|
||||
class Slot extends Component {
|
||||
render() {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import asd from 'coral-framework';
|
||||
console.log(asd)
|
||||
import {client as clientPlugins} from 'pluginsConfig';
|
||||
|
||||
function importer (fill) {
|
||||
@@ -34,25 +32,23 @@ function importer (fill) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
function filterByUserConfig (list) {
|
||||
|
||||
/**
|
||||
* filterByUserConfig will filter the imported files and will only keep the allowed plugins
|
||||
*/
|
||||
return list
|
||||
.filter(plugin => clientPlugins.indexOf(plugin.name) > -1);
|
||||
}
|
||||
|
||||
function addProps (plugin) {
|
||||
|
||||
/**
|
||||
* addProps add properties to the injected plugins
|
||||
*/
|
||||
plugin.props = {...getConfig(plugin.name), plugin: 'true'};
|
||||
plugin.props = {
|
||||
...actionsImporter(),
|
||||
...getConfig(plugin.name)
|
||||
};
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
||||
function filterBySlot (plugin) {
|
||||
/**
|
||||
* filterBySlot
|
||||
*/
|
||||
return plugin.props.slot === fill;
|
||||
}
|
||||
|
||||
@@ -64,12 +60,13 @@ function importer (fill) {
|
||||
*/
|
||||
buildContext();
|
||||
|
||||
return filterByUserConfig(importedFiles)
|
||||
return importedFiles
|
||||
.filter(filterByUserConfig)
|
||||
.filter(key => key.format === 'js')
|
||||
.map(addProps)
|
||||
.filter(filterBySlot)
|
||||
.reduce((entry, plugin, i) => {
|
||||
entry.push(context(plugin.key)({...plugin.props, key: i}));
|
||||
entry = [...entry, context(plugin.key)({...plugin.props, key: i})];
|
||||
return entry;
|
||||
}, []);
|
||||
}
|
||||
@@ -91,16 +88,44 @@ function shapeData(test) {
|
||||
};
|
||||
}
|
||||
|
||||
function filterByUserConfig (plugin) {
|
||||
|
||||
/**
|
||||
* filterByUserConfig will filter the imported files and will only keep the allowed plugins
|
||||
*/
|
||||
return clientPlugins.indexOf(plugin.name) > -1;
|
||||
}
|
||||
|
||||
function importAll(context) {
|
||||
/**
|
||||
* importAll builds the map to import
|
||||
*/
|
||||
return context
|
||||
.keys()
|
||||
.map(key => shapeData(key))
|
||||
.filter(filterByUserConfig)
|
||||
.reduce((entry, actionsPlugin) => {
|
||||
entry[actionsPlugin.name] = context(actionsPlugin.key);
|
||||
return entry;
|
||||
const input = context(actionsPlugin.key);
|
||||
return {...entry, ...input};
|
||||
}, {});
|
||||
}
|
||||
|
||||
function importAllAsArr(context) {
|
||||
/**
|
||||
* importAllAsArr builds the array to import
|
||||
*/
|
||||
return context
|
||||
.keys()
|
||||
.map(key => shapeData(key))
|
||||
.filter(filterByUserConfig)
|
||||
.reduce((entry, graphPlugin) => {
|
||||
const input = context(graphPlugin.key);
|
||||
const res = Object.keys(input)
|
||||
.map(key => input[key]);
|
||||
return [...entry, ...res];
|
||||
}, []);
|
||||
}
|
||||
|
||||
function actionsImporter () {
|
||||
return importAll(require.context('plugins', true, /\.\/(.*)\/client\/actions.js$/));
|
||||
}
|
||||
@@ -110,16 +135,7 @@ function reducersImporter () {
|
||||
}
|
||||
|
||||
function graphImporter () {
|
||||
const context = require.context('plugins', true, /\.\/(.*)\/client\/(queries|mutations)\/index.js$/);
|
||||
return context
|
||||
.keys()
|
||||
.map(key => shapeData(key))
|
||||
.reduce((entry, graphPlugin) => {
|
||||
const input = context(graphPlugin.key);
|
||||
const res = Object.keys(input)
|
||||
.map(key => input[key]);
|
||||
return [...entry, ...res];
|
||||
}, []);
|
||||
return importAllAsArr(require.context('plugins', true, /\.\/(.*)\/client\/(queries|mutations)\/index.js$/));
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -4,7 +4,6 @@ import I18n from './modules/i18n/i18n';
|
||||
import actions from './actions';
|
||||
import Slot from './components/Slot';
|
||||
|
||||
console.log(actions);
|
||||
export default {
|
||||
pym,
|
||||
Slot,
|
||||
|
||||
@@ -3,7 +3,6 @@ import styles from './style.css';
|
||||
|
||||
export default (props) => (
|
||||
<div className={styles.Respect} key={props.key}>
|
||||
{console.log(props)}
|
||||
<button>Respect</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ const initialState = Map({
|
||||
clicked: false
|
||||
});
|
||||
|
||||
export default function reducer (state = initialState, action) {
|
||||
export function respect (state = initialState, action) {
|
||||
switch (action.type) {
|
||||
default:
|
||||
return state;
|
||||
|
||||
Reference in New Issue
Block a user