Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Improve the error messages.
Browse files Browse the repository at this point in the history
Update API.md
  • Loading branch information
MrEfrem committed Nov 26, 2016
1 parent 5d465cf commit 2aa66bb
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/createReducer.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ exports[`test Test listenActions is function in reusable component 1`] = `
</div>
`;
exports[`test Test passed mount path in Component 1`] = `
exports[`test Test passed mounting path in Component 1`] = `
<div>
ui component
</div>
`;
exports[`test Test passed mount path in createReducer and in Component 1`] = `
exports[`test Test passed mounting path in createReducer and in Component 1`] = `
<div>
ui other-component
</div>
Expand Down
20 changes: 10 additions & 10 deletions __tests__/createReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RESET_STATE } from '../src/consts'

test('Test invalid signature', () => {
expect(createReducer).toThrowError('InitialState must be plain object')
expect(createReducer.bind(this, { mountPath: 10, initialState: {} })).toThrowError('Mount path must be string')
expect(createReducer.bind(this, { mountPath: 10, initialState: {} })).toThrowError('Mounting path must be string')
expect(createReducer.bind(this, { mountPath: 'ui component' })).toThrowError('InitialState must be plain object')
expect(createReducer.bind(this, { mountPath: 'ui component', initialState: {}, listenActions: 123 })).toThrowError('ListenActions must be plain object')
expect(createReducer.bind(this, { mountPath: 'ui component', initialState: {}, connectToStore: null })).toThrowError('ConnectToStore must be boolean')
Expand All @@ -24,11 +24,11 @@ test('Test invalid init component', () => {

expect(renderer.create.bind(renderer,
<ExtendedComponent1/>
)).toThrowError('Mount path must be defined')
)).toThrowError('Mounting path must be defined')

expect(renderer.create.bind(renderer,
<ExtendedComponent1 reduxMountPath={['ui component']} />
)).toThrowError('Mount path must be string')
)).toThrowError('Mounting path must be string')

expect(renderer.create.bind(renderer,
<ExtendedComponent1 reduxMountPath="ui component" reduxPersist="true" />
Expand Down Expand Up @@ -148,7 +148,7 @@ test('Test valid init component with provide enhanced redux store', () => {
expect(component.toJSON()).toMatchSnapshot()
})

test('Test passed mount path in Component', () => {
test('Test passed mounting path in Component', () => {
const store = createStore(null, enhanceStore)

const Component = (props) => (
Expand All @@ -167,7 +167,7 @@ test('Test passed mount path in Component', () => {
expect(component.toJSON()).toMatchSnapshot()
})

test('Test passed mount path in createReducer and in Component', () => {
test('Test passed mounting path in createReducer and in Component', () => {
const store = createStore(null, enhanceStore)

const Component = (props) => (
Expand Down Expand Up @@ -781,7 +781,7 @@ test('Test is invalid to create of reducer in same mounting path', () => {
<ExtendedComponent/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component" already busy')
)).toThrowError('Mounting path "ui component" already busy')
})

test('Test is invalid to create of reducer in partially same mounting path (1)', () => {
Expand All @@ -806,7 +806,7 @@ test('Test is invalid to create of reducer in partially same mounting path (1)',
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component" already busy')
)).toThrowError('Mounting path "ui component" already busy')
})

test('Test is invalid to create of reducer in partially same mounting path (2)', () => {
Expand All @@ -831,7 +831,7 @@ test('Test is invalid to create of reducer in partially same mounting path (2)',
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component main" already busy')
)).toThrowError('Mounting path "ui component main" already busy')
})

test('Test is valid to create of reducer after create of reducer', () => {
Expand Down Expand Up @@ -880,7 +880,7 @@ test('Test is invalid to set the mountPath for reused component which contains i
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "todo list" must be contain "ui component"')
)).toThrowError('Mounting path "todo list" must be contain "ui component"')
})

test('Test is invalid to set the mountPath for reused component which contains in other reused component (reduxMountPath + reduxMountPath)', () => {
Expand All @@ -904,7 +904,7 @@ test('Test is invalid to set the mountPath for reused component which contains i
<ExtendedComponent1 reduxMountPath="todo list"/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "todo list" must be contain "ui component"')
)).toThrowError('Mounting path "todo list" must be contain "ui component"')
})

test('Test is valid to set the mountPath for reused component which contains in other reused component', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/enhanceStore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ test('Test registerReducers', () => {
store.registerReducers({ ' ui ': reducer1 })
expect(store.getState().ui).toBe(initialState1)
expect(store.registerReducers({ ui: reducer1 })).toBeUndefined()
expect(store.registerReducers.bind(store, { 'ui component ': reducer1 })).toThrowError('Reducer mount path "ui" already busy')
expect(store.registerReducers.bind(store, { 'ui component ': reducer1 })).toThrowError('Reducer mounting path "ui" already busy')
store.dispatch({ type: 'UPDATE-COMPONENT', text: 'My first updated todo 1' })
expect(JSON.stringify(store.getState())).toBe('{\"ui\":{\"text\":\"My first updated todo 1\"}}')

store.registerReducers({ ' todo list ': reducer2 })
expect(store.registerReducers({ 'todo list': reducer2 })).toBeUndefined()
expect(store.registerReducers.bind(store, { 'todo ': reducer2 })).toThrowError('Reducer mount path "todo list" already busy')
expect(store.registerReducers.bind(store, { 'todo ': reducer2 })).toThrowError('Reducer mounting path "todo list" already busy')
expect(store.registerReducers({ 'todo list1': () => ({}) })).toBeUndefined()

expect(JSON.stringify(store.getState())).toBe('{\"ui\":{\"text\":\"My first updated todo 1\"},\"todo\":{\"list\":{\"text\":\"My second todo\"},\"list1\":{}}}')
Expand Down
6 changes: 3 additions & 3 deletions __tests__/getState.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import getState from '../src/getState'

test('Test invalid signature', () => {
expect(getState).toThrowError('Mount path must be non empty string')
expect(getState.bind(this, 123)).toThrowError('Mount path must be non empty string')
expect(getState.bind(this, '')).toThrowError('Mount path must be non empty string')
expect(getState).toThrowError('Mounting path must be non empty string')
expect(getState.bind(this, 123)).toThrowError('Mounting path must be non empty string')
expect(getState.bind(this, '')).toThrowError('Mounting path must be non empty string')
expect(getState('ui component')).toThrowError('State must be plain object')
expect(getState('ui component').bind(this, 123)).toThrowError('State must be plain object')
})
Expand Down
12 changes: 6 additions & 6 deletions __tests__/registerReducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('Test invalid prop reduxMountPath', () => {

expect(renderer.create.bind(renderer,
<ExtendedComponent1 reduxMountPath={123}/>
)).toThrowError('Mount path must be string')
)).toThrowError('Mounting path must be string')
})

test('Test invalid redux store', () => {
Expand Down Expand Up @@ -200,7 +200,7 @@ test('Test is invalid to register of reducer in same mounting path', () => {
<ExtendedComponent/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component" already busy')
)).toThrowError('Mounting path "ui component" already busy')
})

test('Test is invalid to register of reducer in partially same mounting path (1)', () => {
Expand All @@ -223,7 +223,7 @@ test('Test is invalid to register of reducer in partially same mounting path (1)
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component" already busy')
)).toThrowError('Mounting path "ui component" already busy')
})

test('Test is invalid to register of reducer in partially same mounting path (2)', () => {
Expand All @@ -246,7 +246,7 @@ test('Test is invalid to register of reducer in partially same mounting path (2)
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "ui component main" already busy')
)).toThrowError('Mounting path "ui component main" already busy')
})

test('Test is valid to register of reducer after register of reducer', () => {
Expand Down Expand Up @@ -292,7 +292,7 @@ test('Test is invalid to set the mountPath for reused component which contains i
<ExtendedComponent1/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "reducer2" must be contain "ui component"')
)).toThrowError('Mounting path "reducer2" must be contain "ui component"')
})

test('Test is invalid to set the mountPath for reused component which contains in other reused component (reduxMountPath + reduxMountPath)', () => {
Expand All @@ -315,7 +315,7 @@ test('Test is invalid to set the mountPath for reused component which contains i
<ExtendedComponent1 reduxMountPath="todo list"/>
</ExtendedComponent>
</Provider>
)).toThrowError('Mount path "todo list reducer2" must be contain "ui component"')
)).toThrowError('Mounting path "todo list reducer2" must be contain "ui component"')
})

test('Test is valid to set the mountPath for reused component which contains in other reused component', () => {
Expand Down
8 changes: 6 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ A React component class that injects into your component an Redux state through
#### Remarks
* Mounting path is required and must be transferred through argument and(or) prop.
* If action prefix isn't transferred through argument and prop, then action prefix will be filled to mounting path.
* If Redux store isn't created and isn't provides to components, then Redux store is automatic created with support [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension).
* If prop `reduxMountPath` isn't specified and redux store isn't created and isn't provides to components, then Redux store is automatic created with
support [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension). But if prop `reduxMountPath` is specified and redux
store isn't created and isn't provides to components, then will throwing error, because prop `reduxMountPath` means mount point for state of reused component.

#### Example
```javascript
Expand Down Expand Up @@ -193,7 +195,9 @@ A React component class that register the passed reducers in Redux store.
#### Remarks
* Function must be call two times. The first time with its arguments described above, and a second time, with the component: `registerReducers(reducers)(MyComponent)`.
* Function does not modify the passed React component. It returns a new component that you should use instead.
* If Redux store isn't created and isn't provides to components, then Redux store is automatic created with support [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension).
* If prop `reduxMountPath` isn't specified and redux store isn't created and isn't provides to components, then Redux store is automatic created with
support [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension). But if prop `reduxMountPath` is specified and redux
store isn't created and isn't provides to components, then will throwing error, because prop `reduxMountPath` means mount point for state of reused component.

#### Example

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-fly",
"version": "0.0.1",
"version": "0.0.2",
"description": "Simple redux",
"browser": "dist/redux-fly.js",
"main": "lib/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/createReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default ({
}

if (!mountPath && !propMountPath) {
throw new Error('Mount path must be defined')
throw new Error('Mounting path must be defined')
}
const _mountPath = normalizeMountPath(`${propMountPath || ''} ${mountPath || ''}`)

Expand All @@ -148,10 +148,10 @@ export default ({
((path.indexOf(_mountPath) === 0 && !((path.substr(_mountPath.length)[0] || '').trim())) ||
(_mountPath.indexOf(path) === 0 && !((_mountPath.substr(path.length)[0] || '').trim()))))
) {
throw new Error(`Mount path "${_mountPath}" already busy`)
throw new Error(`Mounting path "${_mountPath}" already busy`)
}
if (this.lastReduxMountPath && _mountPath.indexOf(this.lastReduxMountPath) === -1) {
throw new Error(`Mount path "${_mountPath}" must be contain "${this.lastReduxMountPath}"`)
throw new Error(`Mounting path "${_mountPath}" must be contain "${this.lastReduxMountPath}"`)
}
this.reduxMountPaths.push(_mountPath)

Expand All @@ -165,7 +165,7 @@ export default ({
this.actionPrefix = propActionPrefix
}

// Default value for action prefix contain mount path
// Default value for action prefix contain mounting path
if (!this.actionPrefix) {
if (typeof propMountPath !== 'undefined') {
this.actionPrefix = `${normalizeMountPath(propMountPath)}/`
Expand Down
2 changes: 1 addition & 1 deletion src/enhanceStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const enhanceStore = (createStore: Function) => {
(key1.indexOf(normalizedKey) === 0 && !((key1.substr(normalizedKey.length)[0] || '').trim())))
&& key1 !== normalizedKey
) {
throw new Error(`Reducer mount path "${key1}" already busy`)
throw new Error(`Reducer mounting path "${key1}" already busy`)
}
})
const keys = normalizedKey.split(' ')
Expand Down
2 changes: 1 addition & 1 deletion src/getState.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { normalizeMountPath } from './utils/normalize'
*/
export default (mountPath: string) => {
if (typeof mountPath !== 'string' || !mountPath.length) {
throw new Error('Mount path must be non empty string')
throw new Error('Mounting path must be non empty string')
}
return (state: Object) => {
if (!isPlainObject(state)) {
Expand Down
4 changes: 2 additions & 2 deletions src/registerReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export default (
((path.indexOf(normalizedMountPath) === 0 && !((path.substr(normalizedMountPath.length)[0] || '').trim())) ||
(normalizedMountPath.indexOf(path) === 0 && !((normalizedMountPath.substr(path.length)[0] || '').trim()))))
) {
throw new Error(`Mount path "${normalizedMountPath}" already busy`)
throw new Error(`Mounting path "${normalizedMountPath}" already busy`)
}
if (this.lastReduxMountPath && normalizedMountPath.indexOf(this.lastReduxMountPath) === -1) {
throw new Error(`Mount path "${normalizedMountPath}" must be contain "${this.lastReduxMountPath}"`)
throw new Error(`Mounting path "${normalizedMountPath}" must be contain "${this.lastReduxMountPath}"`)
}
this.reduxMountPaths.push(normalizedMountPath)
_normReducers[normalizedMountPath] = _reducers[key]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/checks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @flow
/**
* Check mountPath
* Check mounting path
* @param {string} path
* @return {void}
*/
export const checkMountPath = (path: any) => {
if (typeof path !== 'string' || !path.trim().length) {
throw new Error('Mount path must be string')
throw new Error('Mounting path must be string')
}
}
4 changes: 2 additions & 2 deletions src/utils/normalize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow
/**
* Trimmed and collapsed spaces in mount path
* Trimmed and collapsed spaces in mounting path
*/
export const normalizeMountPath = (path: any): string => {
if (typeof path !== 'string') {
throw new Error('Mount path must be string')
throw new Error('Mounting path must be string')
}
return path.trim().replace(/\s{2,}/g,' ')
}

0 comments on commit 2aa66bb

Please sign in to comment.