-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new build with rollup & relocated tests
- Loading branch information
Showing
15 changed files
with
197 additions
and
10 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 |
---|---|---|
@@ -1,7 +1,24 @@ | ||
{ | ||
"presets": [ "@babel/preset-env", "@babel/preset-react" ], | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false, | ||
"targets": { | ||
"browsers": ["last 2 Chrome versions", "safari >=11"] | ||
} | ||
}], | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/proposal-class-properties", | ||
"@babel/proposal-object-rest-spread" | ||
] | ||
], | ||
"env": { | ||
"test": { | ||
"presets": ["@babel/preset-env", "@babel/preset-react"], | ||
"plugins": [ | ||
"@babel/proposal-class-properties", | ||
"@babel/proposal-object-rest-spread" | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
|
||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
|
||
/* Export everything, for testing. */ | ||
import { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { clearEvtQueue } from './action-creators'; | ||
export class RRWA extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
_defineProperty(this, "processEvent", ({ | ||
event | ||
}) => { | ||
event(this.audioContext, this.getCurrTime); | ||
}); | ||
|
||
_defineProperty(this, "getCurrTime", () => { | ||
return this.audioContext.currentTime; | ||
}); | ||
|
||
const AudioContext = window.AudioContext || window.webkitAudioContext; | ||
|
||
if (AudioContext) { | ||
this.audioContext = new AudioContext(); | ||
} else { | ||
throw new Error('This environment does not support the web audio API.'); | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
if (this.props.events.length) { | ||
this.props.events.forEach(this.processEvent); | ||
this.props.clearQ(); | ||
} | ||
} | ||
|
||
shouldComponentUpdate(nextProps) { | ||
return nextProps.events.length > 0; | ||
} | ||
|
||
componentDidUpdate() { | ||
if (this.props.events.length) { | ||
this.props.events.forEach(this.processEvent); | ||
this.props.clearQ(); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
this.audioContext.close(); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
|
||
} | ||
export const mapState = ({ | ||
webAudioReducer | ||
}) => _objectSpread({}, webAudioReducer); | ||
export const mapDispatch = dispatch => ({ | ||
clearQ: () => dispatch(clearEvtQueue()) | ||
}); | ||
export default connect(mapState, mapDispatch)(RRWA); |
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,14 @@ | ||
import { QUEUE_EVENT, CLEAR_EVT_QUEUE } from './constants'; | ||
export const clearEvtQueue = () => ({ | ||
type: CLEAR_EVT_QUEUE | ||
}); | ||
/** | ||
* `event` can be a single event or an array of events. An array passed as | ||
* `event` will be concatenated with the current event queue. | ||
* @param {Event | Event[]} event | ||
*/ | ||
|
||
export const emit = event => ({ | ||
type: QUEUE_EVENT, | ||
event | ||
}); |
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,5 @@ | ||
/** @constant */ | ||
export const QUEUE_EVENT = 'QUEUE_EVENT'; | ||
/** @constant */ | ||
|
||
export const CLEAR_EVT_QUEUE = 'CLEAR_EVT_QUEUE'; |
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 @@ | ||
import * as actionCreators from './action-creators'; | ||
import webAudioReducer from './web-audio-reducer'; | ||
import RRWAEngine from './RRWA-component'; | ||
export { RRWAEngine, actionCreators, webAudioReducer }; |
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,45 @@ | ||
import { QUEUE_EVENT, CLEAR_EVT_QUEUE } from './constants'; | ||
/** @constant */ | ||
|
||
const INIT_STATE = { | ||
events: [] | ||
}; | ||
|
||
const webAudioReducer = (state = INIT_STATE, action) => { | ||
const nextState = { | ||
events: [...state.events] | ||
}; | ||
|
||
switch (action.type) { | ||
case QUEUE_EVENT: | ||
queueEvent(state, action, nextState); | ||
break; | ||
|
||
case CLEAR_EVT_QUEUE: | ||
nextState.events = []; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return nextState; | ||
}; | ||
|
||
export default webAudioReducer; | ||
|
||
function queueEvent(state, action, nextState) { | ||
if (Array.isArray(action.event)) { | ||
action.event.forEach((event, idx) => { | ||
nextState.events.push({ | ||
key: state.events.length + idx, | ||
event: event | ||
}); | ||
}); | ||
} else { | ||
nextState.events.push({ | ||
key: state.events.length, | ||
event: action.event | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
|
||
const env = process.env.NODE_ENV; | ||
const pkg = require('./package.json'); | ||
|
||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
file: { | ||
es: pkg.module, | ||
cjs: pkg.main | ||
}[env], | ||
format: env | ||
}, | ||
plugins: [ | ||
resolve({ | ||
customResolveOptions: { | ||
moduleDirectory: 'node_modules' | ||
} | ||
}), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
plugins: ['@babel/external-helpers'], | ||
externalHelpers: true | ||
}), | ||
commonjs(), | ||
terser(), | ||
filesize() | ||
], | ||
external: ['react', 'redux', 'react-redux'] | ||
}; |
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
4 changes: 2 additions & 2 deletions
4
src/test/action-creators.spec.js → test/action-creators.spec.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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/test/web-audio-reducer.spec.js → test/web-audio-reducer.spec.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