-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
Ethorsen
commented
Jun 26, 2018
- Add a mapExtraState option to subspaced enhancer.
- Allow instance enhancers
Q | A |
---|---|
Fixed Issues? | Fixes #9 |
Documentation only PR | |
Patch: Bug Fix? | |
Minor: New Feature? | 👍 |
Major: Breaking Change? | |
Tests Added + Pass? | No |
- Add a mapExtraState option to subspaced enhancer. - Allow instance enhancers
const mapState = (state, rootState) => { | ||
const componentState = state[identifier] | ||
if (!isPlainObject(componentState)) { | ||
// perhaps a warning/error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make a decision one way or the other on these warnings. I'm thinking that this one is ok, as the slice state might legitimately not be a object, but the extraState
should always return an object (otherwise how should it be merged?
if (!isPlainObject(extraState)) {
if (process.env.NODE_ENV !== 'production' && extraState !== null) {
console.warn(`extra state must be a plain object but received ${extraState}`)
}
return componentState
}
I could be convinced that it should throw a TypeError
instead of just warn. @jpeyper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know I'll gladly adapt the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go with a TypeError (because it is a type error and you've used it wrong... Bang!) in dev and "just work" in production.
I think the inclusion in instance enhancers is good, but I'm a little worried that some users may get confused and think that they are able to override the existing enhancers, similarly to have the Any chance of some unit tests for Can I also ask a quick (mostly) unrelated question. I proposed a change to the API to allow identifiers, and possibly enhancer options as props to the |
I was thinking the same, but as they are parameters array I would not know how to de-duplicate/overwrite enhancers of the same type. I also did not want to make a code breaking change.
I'll have a look tomorrow and will try to create and commit tests
I believe that would also work, plus I would not have to keep a reference to the instantiated module. |
Added some tests for new functionalities
}))(ConnectedTestComponent) | ||
|
||
// Silence error thrown by react | ||
console.error = () => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nasty hack but I haven't found a way to silence react error thrown to console. Even adding and error boundary object did not help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this will ever reset console.error
for other tests (possibly hiding useful debugging information)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exhibit B caught my eye
Please also don't forget to add yourself as a contributor |
@@ -0,0 +1,99 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should be in the subspaced.test.js
file. You can put them in a nested describe('mapExtraState tests', ...)
if you want to seperate them from the other tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
|
||
const fakeStore = {} | ||
|
||
const testEnhancer1 = identifier => store => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary but you could avoid duplicating the enhancer code by making this
const testEnhancer = instance => identifier => store => {
expect(identifier).toBe('testId')
expect(store).toBe(fakeStore)
callback(instance)
}
and then calling them like
const DynamicComponent = dynamic('baseId', testEnhancer(1))(TestComponent).createInstance('testId', testEnhancer(2))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
Some tweaks to dynamic tests
import configureStore from 'redux-mock-store' | ||
import { Provider, connect } from 'react-redux' | ||
import { SubspaceProvider } from 'react-redux-subspace' | ||
import { mount } from 'enzyme' | ||
|
||
import dynostore from '../../redux-dynostore-core/lib/index' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was about to merge this then noticed this in my final scan. This is a problematic import for 2 reasons:
- it is pathing outside of the package into another - this is brittle if the other package ever gets refactored
- it's referencing the bundled output, which means the other package would need to be built before this test would work - it's purely coincidental that that occurs as part of bootstrapping lerna for us.
in this case, importing it from the core package as you would any other npm dependency is all that is needed. lerna takes care of the rest for us:
import dynostore from '@redux-dynostore/core'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Sry I missed it, sometimes IDEA does some weird import when you cut/paste code.
Thanks! As a follow up PR (for you or anyone else), a small example demonstrating a use case for this would be very welcome. I might wait for #13 before doing a release, but if it takes more than a few days I'll push this out by itself. |