Skip to content

Commit

Permalink
fix(enhancer): Don't blow up when Web MIDI API unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Jun 4, 2016
1 parent 37a0fb7 commit a9348b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ import observeStore from './observeStore';
import sortBy from 'lodash.sortby';
import deepEqual from 'deep-equal';

const defaultRequestMIDIAccess = global && global.navigator && global.navigator.requestMIDIAccess.bind(global.navigator);
const defaultRequestMIDIAccess = (global && global.navigator && global.navigator.requestMIDIAccess.bind(global.navigator)) || (
() => Promise.reject(new Error('Web MIDI API not available'))
);

/**
* Create a Redux {@link https://github.com/reactjs/redux/blob/master/docs/Glossary.md#store-enhancer|store enhancer} wrapping MIDI I/O and device discovery.
Expand Down
4 changes: 4 additions & 0 deletions test/specs/makeMidiEnhancer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

import { makeMidiEnhancer } from '../../src';
import { createStore } from 'redux';

describe('makeMidiEnhancer', () => {
it('should be a function', () => {
Expand All @@ -9,4 +10,7 @@ describe('makeMidiEnhancer', () => {
it('should be callable with no arguments', () => {
(() => makeMidiEnhancer()).should.not.throw;
});
it('should work as a store enhancer', () => {
createStore(x => (x || {}), makeMidiEnhancer());
});
});

0 comments on commit a9348b9

Please sign in to comment.