-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable support #14
Open
zeevl
wants to merge
2
commits into
gor181:master
Choose a base branch
from
zeevl:immutable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { List, toJS } from 'immutable' | ||
import Reducer from '../reducer'; | ||
import * as Actions from '../actions'; | ||
|
||
describe('reducer', () => { | ||
it('initializes state with an array', () => { | ||
expect(Reducer()).toEqual([]); | ||
expect(Reducer().toJS()).toEqual([]); | ||
}); | ||
|
||
it('stores the notification to state', () => { | ||
const action = Actions.success(); | ||
const state = Reducer([], action); | ||
const state = Reducer(List([]), action); | ||
|
||
expect(state.length).toEqual(1); | ||
expect(state.size).toEqual(1); | ||
}); | ||
|
||
it('stores and removes notification', () => { | ||
const uid = 1; | ||
|
||
const state = Reducer([], Actions.success({ uid })); | ||
expect(state.length).toEqual(1); | ||
const state = Reducer(List([]), Actions.success({ uid })); | ||
expect(state.size).toEqual(1); | ||
|
||
const newState = Reducer(state, Actions.hide(uid)); | ||
expect(newState.length).toEqual(0); | ||
expect(newState.size).toEqual(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hey @zeevl ,
What happens if I'm not using immutable-js? This would fail right?
As native arrays do not have
toJs
method?I have a feeling that if we merge this in then it will break all the existing apps using the lib?
Could be that I need 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.
Might it work if you used
map()
?Both native arrays and Immutable List have the map method (plus decent support for native array.map, IE9+). And you're not directly passing the List or array into the react-notification-system component so it shouldn't affect it.
Bonus would also be not having to perform the
toJS()
call on the notificationsThere 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.
the change to
componentWillReceiveProps
is agnostic to whether the rest of the app is usingimmutable
elsewhere or not, since we're directlyconnect
ingstate.notifications
to the component, i.e. (https://github.com/gor181/react-notification-system-redux/blob/master/example/src/components/container.js#L62). If a consumer follows the docs and examples,nextProps.notifications
will be always be the immutableList
.Edit: take note that the example code didn't change with this PR, but still works as expected..
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.
also, @AverageZ, I don't think
map()
would work -- with this immutable change, the objects in thenotifications
list are also immutable, so they would either require a call totoObject()
,toJS()
some other immutable-specific api.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.
heya @zeevl @AverageZ
thanks for answers, will merge this in by beginning next week 🍻
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.
Hey ppl,
Was thinking about this, and I'm not sure whether we should force people to have immutable-js pulled down as a part of this lib.
What do you think?
Maybe we can make some sort of version which includes immutable as you suggested previously?
Thanks and apologies for late reply.
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.
Guys, there no need any changes for use this lib with immutableJS
Diffrence is only in external usage.
Bellow example ...
File with reducers
Usage in container layer
That is it!
Usage in presentation layer has no any difference
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.
You are definitely wrong, @alameya
"Map" creates new object each time, so you force component to rerender each time you call reducer. This is drastically decrease perfomance.