From b088d1f83946a77949f95dbdc178705e56e02e57 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 29 Feb 2016 17:54:11 -0800 Subject: [PATCH] Update StoreRegistry.js, better errors Better registered errors when store cannot be found. --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- node_package/src/StoreRegistry.js | 6 +++--- node_package/tests/StoreRegistry.test.js | 12 ++++++++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f63809da..6daf72bb91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Items under Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version. ## [Unreleased] +## [3.0.6] - 2016-02-29 +##### Fixed +- Improved errors when registered store is not found. See [#301](https://github.com/shakacode/react_on_rails/pull/301) by [justin808](https://github.com/justin808). + ## [3.0.5] - 2016-02-26 ##### Fixed - Fixed error in linters rake file for generator. See [#299](https://github.com/shakacode/react_on_rails/pull/299) by [mpugach](https://github.com/mpugach). diff --git a/README.md b/README.md index 22e7dfb7fc..4cb51615e8 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ # NEWS * 2016-02-28: We added a [Projects page](PROJECTS.md). Please edit the page your project or [email us](mailto:contact@shakacode.com) and we'll add you. We also love stars as it helps us attract new users and contributors. [jbhatab](https://github.com/jbhatab) is leading an effort to ease the onboarding process for newbies with simpler project generators. See [#245](https://github.com/shakacode/react_on_rails/issues/245). -* 3.0.5 shipped on Friday, 2/26/2016. Please see the [Changelog](CHANGELOG.md) for details, and let us know if you see any issues! [Migration steps from 1.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps-v1-to-v2). [Migration steps from 2.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps-v2-to-v3). - * [RubyGems](https://rubygems.org/gems/react_on_rails/versions/3.0.0.rc.2), `gem "react_on_rails", "~> 3.0.0-rc.2"` - * [NPM](https://www.npmjs.com/package/react-on-rails), `npm i --save react-on-rails@3.0.0-rc.2` +* 3.0.6 shipped on Monday, 2/29/2016. Please see the [Changelog](CHANGELOG.md) for details, and let us know if you see any issues! [Migration steps from 1.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps-v1-to-v2). [Migration steps from 2.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps-v2-to-v3). + * [RubyGems](https://rubygems.org/gems/react_on_rails/) + * [NPM](https://www.npmjs.com/package/react-on-rails) * 3.0.0 Highlights: 1. Support for ensuring JavaScript is current when running tests. 2. Support for multiple React components with one Redux store. So you can have a header React component and different body React components talking to the same Redux store! diff --git a/node_package/src/StoreRegistry.js b/node_package/src/StoreRegistry.js index 548089030c..94af76743e 100644 --- a/node_package/src/StoreRegistry.js +++ b/node_package/src/StoreRegistry.js @@ -22,7 +22,7 @@ export default { }, /** - * Used by components to get the store which contains props (hydrated store). + * Used by components to get the hydrated store which contains props. * @param name * @returns store with given name */ @@ -32,7 +32,7 @@ export default { } else { const storeKeys = Array.from(_stores.keys()).join(', '); console.log('storeKeys', storeKeys); - throw new Error(`Could not find store with name ${name}.\ + throw new Error(`Could not find hydrated store with name '${name}'. \ Hydrated store names include [${storeKeys}].`); } }, @@ -47,7 +47,7 @@ Hydrated store names include [${storeKeys}].`); return _storeGenerators.get(name); } else { const storeKeys = Array.from(_storeGenerators.keys()).join(', '); - throw new Error(`Could not find store registered with name ${name}. \ + throw new Error(`Could not find store registered with name '${name}'. \ Registered store names include [ ${storeKeys} ]. Maybe you forgot to register the store?`); } }, diff --git a/node_package/tests/StoreRegistry.test.js b/node_package/tests/StoreRegistry.test.js index 42d853ad8e..ed05f23a1a 100644 --- a/node_package/tests/StoreRegistry.test.js +++ b/node_package/tests/StoreRegistry.test.js @@ -32,8 +32,8 @@ test('StoreRegistry registers and retrieves generator function stores', (assert) test('StoreRegistry throws error for retrieving unregistered store', (assert) => { assert.plan(1); assert.throws(() => StoreRegistry.getStoreGenerator('foobar'), - /Could not find store registered with name foobar/, - 'Expected an exception for calling StoreRegistry.get with an invalid name.' + /Could not find store registered with name 'foobar'\. Registered store names include/, + 'Expected an exception for calling StoreRegistry.getStoreGenerator with an invalid name.' ); }); @@ -46,3 +46,11 @@ test('StoreRegistry getStore, setStore', (assert) => { assert.deepEqual(actual, expected, 'StoreRegistry should store and retrieve the store'); }); +test('StoreRegistry throws error for retrieving unregistered hydrated store', (assert) => { + assert.plan(1); + assert.throws(() => StoreRegistry.getStore('foobar'), + /Could not find hydrated store with name 'foobar'\. Hydrated store names include/, + 'Expected an exception for calling StoreRegistry.getStore with an invalid name.' + ); +}); +