This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- refactor folder structure; output to lib instead of dist
- create REPLACE_PLUGIN action
- Loading branch information
1 parent
b17d17e
commit 6a1dda5
Showing
18 changed files
with
334 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": [ | ||
"eslint:recommended" | ||
], | ||
"rules": { | ||
"comma-dangle": 2, | ||
"comma-spacing": 2, | ||
"eol-last": 2, | ||
"indent": ["error", 2], | ||
"keyword-spacing": 2, | ||
"linebreak-style": 2, | ||
"no-console": 2, | ||
"no-unused-vars": [2, {"args": "none", "varsIgnorePattern": "React"}], | ||
"no-extra-semi": 2, | ||
"no-trailing-spaces": 2, | ||
"no-unexpected-multiline": 2, | ||
"no-unreachable": 2, | ||
"semi": ["error", "never"] | ||
}, | ||
"env": { | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
lib | ||
testlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
src/test | ||
dist/test | ||
test | ||
testlib | ||
spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"spec_dir": "dist/test", | ||
"spec_dir": "testlib/test", | ||
"spec_files": [ | ||
"**/*.js" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "eslint:recommended", | ||
"ecmaFeatures": { | ||
"modules": true, | ||
}, | ||
"rules": { | ||
"comma-dangle": 0, | ||
"no-unused-vars": [1, {"args": "none", "varsIgnorePattern": "React"}], | ||
"strict": 0, | ||
}, | ||
"env": { | ||
"browser": true | ||
"browser": true, | ||
"node": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as pluginActions from './lib/pluginActions'; | ||
import pluginMiddleware from './lib/pluginMiddleware'; | ||
import pluginReducer from './lib/pluginReducer'; | ||
import * as pluginTypes from './lib/pluginTypes'; | ||
import * as pluginActions from './pluginActions' | ||
import pluginMiddleware from './pluginMiddleware' | ||
import pluginReducer from './pluginReducer' | ||
import * as pluginTypes from './pluginTypes' | ||
|
||
export {pluginActions, pluginMiddleware, pluginReducer, pluginTypes}; | ||
export {pluginActions, pluginMiddleware, pluginReducer, pluginTypes} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,47 @@ | ||
/* @flow */ | ||
|
||
import * as Immutable from 'immutable'; | ||
import type {LoadStatus} from './pluginTypes'; | ||
import type {Action} from './reduxTypes'; | ||
import * as Immutable from 'immutable' | ||
import type {LoadStatus} from './pluginTypes' | ||
import type {Action} from './reduxTypes' | ||
|
||
export const ADD_PLUGIN = 'ADD_PLUGIN'; | ||
export const LOAD_PLUGIN = 'LOAD_PLUGIN'; | ||
export const INSTALL_PLUGIN = 'INSTALL_PLUGIN'; | ||
export const SET_PLUGIN_STATUS = 'SET_PLUGIN_STATUS'; | ||
export const ADD_PLUGIN = 'ADD_PLUGIN' | ||
export const REPLACE_PLUGIN = 'REPLACE_PLUGIN' | ||
export const LOAD_PLUGIN = 'LOAD_PLUGIN' | ||
export const INSTALL_PLUGIN = 'INSTALL_PLUGIN' | ||
export const SET_PLUGIN_STATUS = 'SET_PLUGIN_STATUS' | ||
|
||
export function addPlugin(plugin: Immutable.Collection): Action { | ||
return { | ||
type: ADD_PLUGIN, | ||
payload: plugin | ||
}; | ||
} | ||
} | ||
|
||
export function replacePlugin(plugin: Immutable.Collection): Action { | ||
return { | ||
type: REPLACE_PLUGIN, | ||
payload: plugin | ||
} | ||
} | ||
|
||
export function loadPlugin(key: string): Action { | ||
return { | ||
type: LOAD_PLUGIN, | ||
payload: key | ||
}; | ||
} | ||
} | ||
|
||
export function installPlugin(plugin: Immutable.Collection): Action { | ||
return { | ||
type: INSTALL_PLUGIN, | ||
payload: plugin | ||
}; | ||
} | ||
} | ||
|
||
export function setPluginStatus(key: string, payload: {loadStatus?: LoadStatus, loadError?: Error}): Action { | ||
return { | ||
type: SET_PLUGIN_STATUS, | ||
payload, | ||
meta: {key} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import * as Immutable from 'immutable'; | ||
import Promise from 'bluebird'; | ||
import * as Immutable from 'immutable' | ||
import Promise from 'bluebird' | ||
|
||
import {createSelector} from 'reselect'; | ||
import {createSelector} from 'reselect' | ||
|
||
import {createMiddleware, composeMiddleware} from 'mindfront-redux-utils'; | ||
import {createMiddleware, composeMiddleware} from 'mindfront-redux-utils' | ||
|
||
import {LOADING, NOT_LOADED, LOADED} from './pluginTypes'; | ||
import {LOADING, NOT_LOADED, LOADED} from './pluginTypes' | ||
|
||
import type {Middleware} from './reduxTypes'; | ||
import type {Middleware} from './reduxTypes' | ||
|
||
import { | ||
setPluginStatus, | ||
LOAD_PLUGIN, | ||
installPlugin, | ||
} from './pluginActions'; | ||
installPlugin | ||
} from './pluginActions' | ||
|
||
const loadPluginHandler: Middleware = store => next => action => { | ||
next(action); | ||
next(action) | ||
|
||
let key = action.payload; | ||
let plugin = store.getState().getIn(['plugins', key]); | ||
let key = action.payload | ||
let plugin = store.getState().getIn(['plugins', key]) | ||
if (plugin) { | ||
if (plugin.get('loadStatus') === LOADED) { | ||
return Promise.resolve(plugin); | ||
return Promise.resolve(plugin) | ||
} | ||
let load = plugin.get('load'); | ||
let load = plugin.get('load') | ||
if (!(load instanceof Function)) { | ||
return Promise.reject(new Error(`plugin must have loaded status or a load method`)); | ||
return Promise.reject(new Error(`plugin must have loaded status or a load method`)) | ||
} | ||
store.dispatch(setPluginStatus(key, {loadStatus: LOADING})); | ||
store.dispatch(setPluginStatus(key, {loadStatus: LOADING})) | ||
|
||
let returnedPromise; | ||
let returnedPromise | ||
let callbackPromise = Promise.fromNode(callback => { | ||
returnedPromise = load(store, callback); | ||
}); | ||
returnedPromise = load(store, callback) | ||
}) | ||
|
||
return (returnedPromise || callbackPromise).catch((error: Error) => { | ||
store.dispatch(setPluginStatus(key, {loadStatus: NOT_LOADED, loadError: error})); | ||
throw error; | ||
store.dispatch(setPluginStatus(key, {loadStatus: NOT_LOADED, loadError: error})) | ||
throw error | ||
}) | ||
.then((plugin: Immutable.Collection) => { | ||
if (plugin instanceof Immutable.Collection) { | ||
store.dispatch(installPlugin(plugin.set('key', key))); | ||
return plugin; | ||
store.dispatch(installPlugin(plugin.set('key', key))) | ||
return plugin | ||
} | ||
else { | ||
throw new Error('plugin must be an Immutable.Collection'); | ||
throw new Error('plugin must be an Immutable.Collection') | ||
} | ||
}); | ||
}) | ||
} | ||
else { | ||
return Promise.reject(new Error(`no plugin with key '${key}' exists`)); | ||
return Promise.reject(new Error(`no plugin with key '${key}' exists`)) | ||
} | ||
}; | ||
} | ||
|
||
const selectPluginMiddleware: (state: Immutable.Collection) => Middleware = createSelector( | ||
state => state.get('plugins'), | ||
plugins => plugins ? | ||
composeMiddleware(...plugins.map(p => p.get('middleware')).toArray()) : | ||
store => next => action => next(action) | ||
); | ||
) | ||
|
||
export default composeMiddleware( | ||
createMiddleware({ | ||
[LOAD_PLUGIN]: loadPluginHandler | ||
}), | ||
store => next => action => selectPluginMiddleware(store.getState())(store)(next)(action) | ||
); | ||
) |
Oops, something went wrong.