From a9348b983b17902e8c7ace8aaa2b5c8823e5cb47 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Sat, 4 Jun 2016 12:55:41 +0300 Subject: [PATCH] fix(enhancer): Don't blow up when Web MIDI API unavailable --- src/index.js | 4 +++- test/specs/makeMidiEnhancer.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 685a206..f38485b 100644 --- a/src/index.js +++ b/src/index.js @@ -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. diff --git a/test/specs/makeMidiEnhancer.js b/test/specs/makeMidiEnhancer.js index 14c6581..a74c9d1 100644 --- a/test/specs/makeMidiEnhancer.js +++ b/test/specs/makeMidiEnhancer.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ import { makeMidiEnhancer } from '../../src'; +import { createStore } from 'redux'; describe('makeMidiEnhancer', () => { it('should be a function', () => { @@ -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()); + }); });