Skip to content

Commit

Permalink
Use warning package
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Oct 10, 2015
1 parent 57c0776 commit 548e230
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 39 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions src/alt/actions/index.js
Expand Up @@ -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) => {
Expand Down
20 changes: 9 additions & 11 deletions src/alt/index.js
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions src/alt/utils/AltUtils.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/es3-module-pattern.js
Expand Up @@ -40,7 +40,7 @@ export default {
'Creating store using ES3 module pattern': {
beforeEach() {
alt.recycle()
console.warn = function () { }
console.error = function () { }
},

'store method exists'() {
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Expand Up @@ -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 = {
Expand All @@ -374,7 +374,7 @@ const tests = {
altInstance.recycle()
alt1.recycle()
alt2.recycle()
console.warn = consoleWarn
console.error = consoleErr
},

'alt instance'() {
Expand Down
10 changes: 4 additions & 6 deletions test/stores-with-colliding-names.js
Expand Up @@ -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'() {
Expand All @@ -20,7 +20,6 @@ export default {
alt.createStore(MyStore)

assert.isObject(alt.stores.MyStore1, 'a store was still created')

},

'colliding names via identifier'() {
Expand All @@ -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')
},
}
}

0 comments on commit 548e230

Please sign in to comment.