diff --git a/package.json b/package.json index c04a4ed1..855a9b06 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "lib", "dependencies": { "flux": "2.0.3", - "transmitter": "1.0.2" + "transmitter": "1.0.2", + "warning": "2.0.0" }, "devDependencies": { "alt-search-docs": "1.0.6", diff --git a/src/alt/actions/index.js b/src/alt/actions/index.js index 3aa77d91..bc9e43b8 100644 --- a/src/alt/actions/index.js +++ b/src/alt/actions/index.js @@ -40,15 +40,6 @@ export default function makeAction(alt, namespace, name, implementation, obj) { } } - if (!newAction.dispatched && result === undefined) { - /* istanbul ignore else */ - /*eslint-disable*/ - if (typeof console !== 'undefined') { - console.warn('An action was called but nothing was dispatched') - } - /*eslint-enable*/ - } - return result } action.defer = (...args) => { diff --git a/src/alt/index.js b/src/alt/index.js index 2ef48902..d8a9f861 100644 --- a/src/alt/index.js +++ b/src/alt/index.js @@ -6,6 +6,7 @@ import * as fn from '../utils/functions' import * as store from './store' import * as utils from './utils/AltUtils' import makeAction from './actions' +import warning from 'warning' class Alt { constructor(config = {}) { @@ -58,18 +59,15 @@ class Alt { /* istanbul ignore next */ if (module.hot) delete this.stores[key] - if (this.stores[key] || !key) { - if (this.stores[key]) { - utils.warn( - `A store named ${key} already exists, double check your store ` + - `names or pass in your own custom identifier for each store` - ) - } else { - utils.warn('Store name was not specified') - } + warning( + !this.stores.hasOwnProperty(key), + `A store named ${key} already exists, double check your store ` + + `names or pass in your own custom identifier for each store` + ) - key = utils.uid(this.stores, key) - } + warning(key, 'Store name was not specified') + + if (this.stores[key] || !key) key = utils.uid(this.stores, key) const storeInstance = fn.isFunction(Store) ? store.createStoreFromClass(this, Store, key, ...args) diff --git a/src/alt/utils/AltUtils.js b/src/alt/utils/AltUtils.js index ed293417..c3382a85 100644 --- a/src/alt/utils/AltUtils.js +++ b/src/alt/utils/AltUtils.js @@ -18,15 +18,6 @@ export function getInternalMethods(Obj, isProto) { }, {}) } -export function warn(msg) { - /* istanbul ignore else */ - /*eslint-disable*/ - if (typeof console !== 'undefined') { - console.warn(new ReferenceError(msg)) - } - /*eslint-enable*/ -} - export function uid(container, name) { let count = 0 let key = name diff --git a/test/es3-module-pattern.js b/test/es3-module-pattern.js index a44d5efd..4d2da545 100644 --- a/test/es3-module-pattern.js +++ b/test/es3-module-pattern.js @@ -40,7 +40,7 @@ export default { 'Creating store using ES3 module pattern': { beforeEach() { alt.recycle() - console.warn = function () { } + console.error = function () { } }, 'store method exists'() { diff --git a/test/index.js b/test/index.js index 2951aa47..a78c7498 100644 --- a/test/index.js +++ b/test/index.js @@ -365,7 +365,7 @@ NameStore.prototype.onUpdateName = function (name) { const nameStore1 = alt1.createStore(NameStore) const nameStore2 = alt2.createStore(NameStore) -const consoleWarn = console.warn.bind(console) +const consoleErr = console.error.bind(console) /* istanbul ignore next */ const tests = { @@ -374,7 +374,7 @@ const tests = { altInstance.recycle() alt1.recycle() alt2.recycle() - console.warn = consoleWarn + console.error = consoleErr }, 'alt instance'() { diff --git a/test/stores-with-colliding-names.js b/test/stores-with-colliding-names.js index d4f99456..a09370c0 100644 --- a/test/stores-with-colliding-names.js +++ b/test/stores-with-colliding-names.js @@ -7,10 +7,10 @@ const alt = new Alt() alt.createStore(function MyStore() { }) export default { - 'console warn for missing identifier': { + 'console error for missing identifier': { beforeEach() { - console.warn = sinon.stub() - console.warn.returnsArg(0) + console.error = sinon.stub() + console.error.returnsArg(0) }, 'stores with colliding names'() { @@ -20,7 +20,6 @@ export default { alt.createStore(MyStore) assert.isObject(alt.stores.MyStore1, 'a store was still created') - }, 'colliding names via identifier'() { @@ -37,8 +36,7 @@ export default { }, afterEach() { - assert.ok(console.warn.calledOnce, 'the warning was called') - assert.instanceOf(console.warn.returnValues[0], ReferenceError, 'value returned is an instanceof referenceerror') + assert.ok(console.error.calledOnce, 'the erroring was called') }, } }