-
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.
- Loading branch information
0 parents
commit 5bbe968
Showing
8 changed files
with
144 additions
and
0 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,16 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "airbnb", | ||
"rules": { | ||
"comma-dangle": [2, "never"], | ||
"brace-style": [2, "stroustrup"], | ||
"new-cap": [2, { "newIsCap": true, "capIsNew": false }], | ||
"func-names": 2, | ||
"no-sequences": 0, | ||
"no-unused-vars": 2, | ||
"no-param-reassign": [2, {"props": false}] | ||
}, | ||
"env": { | ||
"mocha": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,4 @@ | ||
module.exports = { | ||
emitterMiddleware: require('./lib/emitterMiddleware').default, | ||
eventReducer: require('./lib/eventReducer').default | ||
} |
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,17 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var emitterMiddleware = function emitterMiddleware() { | ||
return function (next) { | ||
return function (event, data) { | ||
return data ? next(_extends({ type: event }, data)) : next(event); | ||
}; | ||
}; | ||
}; | ||
|
||
exports.default = emitterMiddleware; |
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,37 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var eventReducer = function eventReducer(initialState) { | ||
var listeners = {}; | ||
var reducer = function reducer() { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0]; | ||
var action = arguments[1]; | ||
return reducer.emit(action && action.type, state, action); | ||
}; | ||
|
||
reducer.on = function (event, fn) { | ||
(listeners[event] || (listeners[event] = [])).push(fn); | ||
return reducer; | ||
}; | ||
|
||
reducer.removeListener = function (event, fn) { | ||
var index = listeners[event] && listeners[event].indexOf(fn); | ||
if (index > -1) { | ||
listeners[event].splice(index, 1); | ||
} | ||
}; | ||
|
||
reducer.emit = function (event, state, action) { | ||
return (event && listeners[event] || []).reduce(function (nextstate, listener) { | ||
return listener(nextstate, action); | ||
}, state); | ||
}; | ||
|
||
reducer.listeners = listeners; | ||
|
||
return reducer; | ||
}; | ||
|
||
exports.default = eventReducer; |
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,38 @@ | ||
{ | ||
"name": "redux-actionemitter", | ||
"version": "1.0.0", | ||
"description": "Redux Action Emitter", | ||
"main": "index.js", | ||
"scripts": { | ||
"watch": "babel --watch --presets es2015,stage-2 -d lib/ src/", | ||
"compile": "babel --presets es2015,stage-2 -d lib/ src/", | ||
"prepublish": "npm run compile", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"Action", | ||
"Redux", | ||
"Middleware", | ||
"EventEmitter" | ||
], | ||
"author": "Sam Gentle <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.5.1", | ||
"babel-eslint": "^4.1.8", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"eslint": "^1.10.3", | ||
"eslint-config-airbnb": "^5.0.0", | ||
"eslint-plugin-react": "^3.16.1" | ||
}, | ||
"dependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sgentle/redux-actionemitter.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sgentle/redux-actionemitter/issues" | ||
}, | ||
"homepage": "https://github.com/sgentle/redux-actionemitter" | ||
} |
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,4 @@ | ||
const emitterMiddleware = () => next => (event, data) => | ||
data ? next({ type: event, ...data }) : next(event); | ||
|
||
export default emitterMiddleware; |
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,27 @@ | ||
const eventReducer = (initialState) => { | ||
const listeners = {}; | ||
const reducer = (state = initialState, action) => | ||
reducer.emit(action && action.type, state, action); | ||
|
||
reducer.on = (event, fn) => { | ||
(listeners[event] || (listeners[event] = [])).push(fn); | ||
return reducer; | ||
}; | ||
|
||
reducer.removeListener = (event, fn) => { | ||
const index = listeners[event] && listeners[event].indexOf(fn); | ||
if (index > -1) { | ||
listeners[event].splice(index, 1); | ||
} | ||
}; | ||
|
||
reducer.emit = (event, state, action) => | ||
(event && listeners[event] || []) | ||
.reduce((nextstate, listener) => listener(nextstate, action), state); | ||
|
||
reducer.listeners = listeners; | ||
|
||
return reducer; | ||
}; | ||
|
||
export default eventReducer; |