Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #100 from NikitaKolokoltsev/fix-prefilled-state
Browse files Browse the repository at this point in the history
add defaultState from the original reducers to the namespaced ones
  • Loading branch information
mpeyper authored Dec 13, 2018
2 parents 7e1714f + 5558650 commit ac618ea
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
14 changes: 13 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@
"contributions": [
"talk"
]
},
{
"login": "NikitaKolokoltsev",
"name": "Nikita",
"avatar_url": "https://avatars2.githubusercontent.com/u/15002250?v=4",
"profile": "https://github.com/NikitaKolokoltsev",
"contributions": [
"bug",
"code",
"test"
]
}
]
],
"repoType": "github"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm downloads](https://img.shields.io/npm/dm/redux-subspace.svg?style=flat-square)](https://www.npmjs.com/package/redux-subspace)
[![License: BSD-3-Clause](https://img.shields.io/npm/l/redux-subspace.svg?style=flat-square)](/LICENSE.md)

[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

[![Watch on GitHub](https://img.shields.io/github/watchers/ioof-holdings/redux-subspace.svg?style=social)](https://github.com/ioof-holdings/redux-subspace/watchers)
Expand Down Expand Up @@ -87,7 +87,7 @@ Thanks goes to these wonderful people ([emojis](https://github.com/kentcdodds/al
| [<img src="https://avatars0.githubusercontent.com/u/23029903?v=4" width="100px;"/><br /><sub><b>Michael Peyper</b></sub>](https://github.com/mpeyper)<br />[💬](#question-mpeyper "Answering Questions") [🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3Ampeyper "Bug reports") [💻](https://github.com/ioof-holdings/redux-subspace/commits?author=mpeyper "Code") [📖](https://github.com/ioof-holdings/redux-subspace/commits?author=mpeyper "Documentation") [💡](#example-mpeyper "Examples") [🤔](#ideas-mpeyper "Ideas, Planning, & Feedback") [🚇](#infra-mpeyper "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-mpeyper "Reviewed Pull Requests") [📦](#platform-mpeyper "Packaging/porting to new platform") [📢](#talk-mpeyper "Talks") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=mpeyper "Tests") [🔧](#tool-mpeyper "Tools") | [<img src="https://avatars2.githubusercontent.com/u/6560018?v=4" width="100px;"/><br /><sub><b>Jonathan Peyper</b></sub>](https://github.com/jpeyper)<br />[💬](#question-jpeyper "Answering Questions") [💻](https://github.com/ioof-holdings/redux-subspace/commits?author=jpeyper "Code") [🤔](#ideas-jpeyper "Ideas, Planning, & Feedback") [👀](#review-jpeyper "Reviewed Pull Requests") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=jpeyper "Tests") | [<img src="https://avatars3.githubusercontent.com/u/1409738?v=4" width="100px;"/><br /><sub><b>Vivian Farrell</b></sub>](https://github.com/vivian-farrell)<br />[🤔](#ideas-vivian-farrell "Ideas, Planning, & Feedback") [📦](#platform-vivian-farrell "Packaging/porting to new platform") [👀](#review-vivian-farrell "Reviewed Pull Requests") [📢](#talk-vivian-farrell "Talks") | [<img src="https://avatars2.githubusercontent.com/u/971283?v=4" width="100px;"/><br /><sub><b>Emily Rosengren</b></sub>](https://github.com/emirose)<br />[📢](#talk-emirose "Talks") | [<img src="https://avatars1.githubusercontent.com/u/121742?v=4" width="100px;"/><br /><sub><b>Morgan Larosa</b></sub>](https://github.com/chaos95)<br />[🚇](#infra-chaos95 "Infrastructure (Hosting, Build-Tools, etc)") | [<img src="https://avatars2.githubusercontent.com/u/656565?v=4" width="100px;"/><br /><sub><b>Amit Kothari</b></sub>](http://amitkothari.com)<br />[💻](https://github.com/ioof-holdings/redux-subspace/commits?author=amitkothari "Code") [💡](#example-amitkothari "Examples") | [<img src="https://avatars3.githubusercontent.com/u/1206987?v=4" width="100px;"/><br /><sub><b>Riku Rouvila</b></sub>](http://rikurouvila.fi)<br />[💻](https://github.com/ioof-holdings/redux-subspace/commits?author=rikukissa "Code") [📖](https://github.com/ioof-holdings/redux-subspace/commits?author=rikukissa "Documentation") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=rikukissa "Tests") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars2.githubusercontent.com/u/2007370?v=4" width="100px;"/><br /><sub><b>Michael</b></sub>](https://github.com/mradionov)<br />[💻](https://github.com/ioof-holdings/redux-subspace/commits?author=mradionov "Code") | [<img src="https://avatars0.githubusercontent.com/u/9067274?v=4" width="100px;"/><br /><sub><b>James Adams</b></sub>](https://medium.com/@jamesadams0)<br />[📖](https://github.com/ioof-holdings/redux-subspace/commits?author=James-E-Adams "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/21031458?v=4" width="100px;"/><br /><sub><b>Lee Kyles</b></sub>](https://github.com/lkyles1991)<br />[💻](https://github.com/ioof-holdings/redux-subspace/commits?author=lkyles1991 "Code") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=lkyles1991 "Tests") | [<img src="https://avatars1.githubusercontent.com/u/6398211?v=4" width="100px;"/><br /><sub><b>Evert Bouw</b></sub>](https://github.com/evertbouw)<br />[💻](https://github.com/ioof-holdings/redux-subspace/commits?author=evertbouw "Code") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=evertbouw "Tests") [📖](https://github.com/ioof-holdings/redux-subspace/commits?author=evertbouw "Documentation") [💡](#example-evertbouw "Examples") | [<img src="https://avatars0.githubusercontent.com/u/4831814?v=4" width="100px;"/><br /><sub><b>Paweł Bród</b></sub>](https://github.com/Crazy-Ivan)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3ACrazy-Ivan "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/2294352?v=4" width="100px;"/><br /><sub><b>majo44</b></sub>](https://github.com/majo44)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3Amajo44 "Bug reports") [💻](https://github.com/ioof-holdings/redux-subspace/commits?author=majo44 "Code") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=majo44 "Tests") | [<img src="https://avatars1.githubusercontent.com/u/26989071?v=4" width="100px;"/><br /><sub><b>Garth Newton</b></sub>](https://github.com/garth-newton)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3Agarth-newton "Bug reports") [📖](https://github.com/ioof-holdings/redux-subspace/commits?author=garth-newton "Documentation") |
| [<img src="https://avatars2.githubusercontent.com/u/9800850?v=4" width="100px;"/><br /><sub><b>Mateusz Burzyński</b></sub>](https://github.com/Andarist)<br />[🔧](#tool-Andarist "Tools") | [<img src="https://avatars3.githubusercontent.com/u/6784822?v=4" width="100px;"/><br /><sub><b>psamusev</b></sub>](https://github.com/psamusev)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3Apsamusev "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/762949?v=4" width="100px;"/><br /><sub><b>Jay Phelps</b></sub>](https://twitter.com/_jayphelps)<br />[👀](#review-jayphelps "Reviewed Pull Requests") | [<img src="https://avatars1.githubusercontent.com/u/1128784?v=4" width="100px;"/><br /><sub><b>Mark Erikson</b></sub>](http://blog.isquaredsoftware.com)<br />[📢](#talk-markerikson "Talks") |
| [<img src="https://avatars2.githubusercontent.com/u/9800850?v=4" width="100px;"/><br /><sub><b>Mateusz Burzyński</b></sub>](https://github.com/Andarist)<br />[🔧](#tool-Andarist "Tools") | [<img src="https://avatars3.githubusercontent.com/u/6784822?v=4" width="100px;"/><br /><sub><b>psamusev</b></sub>](https://github.com/psamusev)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3Apsamusev "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/762949?v=4" width="100px;"/><br /><sub><b>Jay Phelps</b></sub>](https://twitter.com/_jayphelps)<br />[👀](#review-jayphelps "Reviewed Pull Requests") | [<img src="https://avatars1.githubusercontent.com/u/1128784?v=4" width="100px;"/><br /><sub><b>Mark Erikson</b></sub>](http://blog.isquaredsoftware.com)<br />[📢](#talk-markerikson "Talks") | [<img src="https://avatars2.githubusercontent.com/u/15002250?v=4" width="100px;"/><br /><sub><b>Nikita</b></sub>](https://github.com/NikitaKolokoltsev)<br />[🐛](https://github.com/ioof-holdings/redux-subspace/issues?q=author%3ANikitaKolokoltsev "Bug reports") [💻](https://github.com/ioof-holdings/redux-subspace/commits?author=NikitaKolokoltsev "Code") [⚠️](https://github.com/ioof-holdings/redux-subspace/commits?author=NikitaKolokoltsev "Tests") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
Expand Down
5 changes: 3 additions & 2 deletions packages/redux-subspace/src/actions/isGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const REDUX_PREFIX = '@@redux/'

const isGlobal = (action) => !action.type || action.globalAction === true
const isGlobal = (action) => !action.type || action.globalAction === true || action.type.startsWith(REDUX_PREFIX)

export default isGlobal
export default isGlobal
8 changes: 8 additions & 0 deletions packages/redux-subspace/test/actions/isGlobal-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ describe('isGlobal tests', () => {

expect(isGlobal(action)).to.be.ok
})

it('should be global if it is a redux-specific action', () => {
const type = '@@redux/INIT' + Math.random().toString(36).substring(7).split('').join('.')

const action = () => ({ type })

expect(isGlobal(action)).to.be.ok
})
})
20 changes: 15 additions & 5 deletions packages/redux-subspace/test/actions/processAction-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,49 @@ describe('processAction Tests', () => {
it('should process action if no namespace provided', () => {
const action = { type: 'test/TEST', value: 'expected' }
const callback = sinon.mock().returns(true)

expect(processAction()(action, callback)).to.true
expect(callback).to.be.calledWithMatch({ type: 'test/TEST', value: 'expected' })
})

it('should process action if action is redux-specific', () => {
const type = '@@redux/INIT' + Math.random().toString(36).substring(7).split('').join('.')

const action = { type }
const callback = sinon.mock().returns(true)

expect(processAction()(action, callback)).to.true
expect(callback).to.be.calledWithMatch({ type })
})

it('should process action with provided namespace', () => {
const action = { type: 'test/TEST', value: 'expected' }
const callback = sinon.mock().returns(true)

expect(processAction('test')(action, callback)).to.true
expect(callback).to.be.calledWithMatch({ type: 'TEST', value: 'expected' })
})

it('should process global action with provided namespace', () => {
const action = { type: 'TEST', value: 'expected', globalAction: true }
const callback = sinon.mock().returns(true)

expect(processAction('test')(action, callback)).to.true
expect(callback).to.be.calledWithMatch({ type: 'TEST', value: 'expected', globalAction: true })
})

it('should ignore action without provided namespace', () => {
const action = { type: 'TEST', value: 'expected' }
const callback = sinon.mock().throws()

expect(processAction('test')(action, callback)).to.be.undefined
expect(callback).to.not.be.calledWithMatch({ type: 'TEST', value: 'expected' })
})

it('should return default value when action is ignored', () => {
const action = { type: 'TEST', value: 'expected' }
const callback = sinon.mock().throws()

expect(processAction('test')(action, callback, true)).to.be.true
expect(callback).to.not.be.calledWithMatch({ type: 'TEST', value: 'expected' })
})
Expand Down

0 comments on commit ac618ea

Please sign in to comment.