Skip to content
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

Added shift toggle #47

Merged
merged 9 commits into from
Jan 3, 2017
Merged

Conversation

khankuan
Copy link
Contributor

@khankuan khankuan commented Apr 3, 2016

No description provided.

@@ -72,6 +72,10 @@ export default class LogMonitor extends Component {

shouldComponentUpdate = shouldPureComponentUpdate;

state = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use monitorState and reducers for that? We already have a reducer tracking current scroll top, for example. Local state will get erased on reload, but with persistState(), monitorState will not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're totally right. Can't believe i didn't notice the reducer.js and action.js..

@gaearon
Copy link
Owner

gaearon commented Apr 3, 2016

Do you mind providing a GIF showing how it works?

@khankuan
Copy link
Contributor Author

khankuan commented Apr 3, 2016

Hmm, i was using redux-devtools-extension and realised that its not using the default instrument. In that case, the reducer is not in used. Any thoughts about it?

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Apr 4, 2016

We use default instrument in redux-devtools-extension, but the monitors are outside the app side (and the instrument enhancer). So, yes the monitors reducers have no effect there, but will be fixed in zalmoxisus/redux-devtools-extension#87.

@@ -160,7 +161,7 @@ export default class LogMonitor extends Component {

handleToggleConsecutiveAction(id) {
const { consecutiveToggleStartId } = this.props.monitorState;
if (consecutiveToggleStartId !== null) {
if (consecutiveToggleStartId > -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works only first time, while consecutiveToggleStartId is undefined and the condition is not satisfied. Next time consecutiveToggleStartId will be set to null and null > -1. So it will be always interpreted as a starting point, and there won't be possible to set another start point than null anymore.

Why not just to have if (consecutiveToggleStartId)? It will also prevent toggling the first INIT state. I tried and this fixes the issue.

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Oct 21, 2016

@khankuan, I'd like to merge this. If you could find time to fix the conflicts, I'll review it and will add support for monitor reducers in the extension.

Also, would be nice to identify actions to be toggled in some other way. Maybe an interrupted or flashing line?

@khankuan
Copy link
Contributor Author

@zalmoxisus cool :) I've fixed the merge conflicts. However, I would like to get some help on the best way to run and test the monitor visually.

@zalmoxisus
Copy link
Collaborator

I guess the easier way would be to have an example here. For now you can:

  1. Run npm link here.
  2. Clone redux-devtools repo and npm install.
  3. Chose an example, for example cd examples/todomvc, and do npm install.
  4. Remove redux-devtools-log-monitor from there (rm -rf node_modules/redux-devtools-log-monitor).
  5. Run npm link redux-devtools-log-monitor.

@khankuan
Copy link
Contributor Author

Hey, i've updated the branch and tested. Used opacity for selected state instead. I'm interested in the flashing line, would it required redux-devtools-theme to take in css?

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Oct 31, 2016

@khankuan, css animation with inline styles is a pain. I think we could just keep your implementation with opacity, marking that it's still not applied. Maybe you have any other ideas of showing that the action is still in process?

@khankuan
Copy link
Contributor Author

khankuan commented Nov 1, 2016

Here's how it feels like now:

output

@zalmoxisus
Copy link
Collaborator

@khankuan, looks great, thanks. There's still an issue here to be addressed.

@khankuan
Copy link
Contributor Author

khankuan commented Nov 2, 2016

Hmm I dont see it. Is the review in draft mode?

@zalmoxisus
Copy link
Collaborator

@khankuan, weird :)

The reducer works ok, but, when having other actions dispatched meantime, the selection is lost.

Returning null for other than START_CONSECUTIVE_TOGGLE actions here, leads to unexpected behaviours. For example, when scrolling, initialScrollTop is dispatched and the selection gets dismissed. Also, I guess wile selecting some app's actions can dispatched and we don't want to lose the selection.

I'd suggest to dismiss the selection only when regular COMMIT is dispatched. However, we cannot handle this case here as for the extension we call monitors reducers only for its actions. So, a solution is when dispatching COMMIT, to dispatch also { type: START_CONSECUTIVE_TOGGLE, id: null }.

Another case is when the selected action got removed (due to commiting, reseting, reaching maxAge...), for that we shouldn't take it into consideration just by checking if it's present when making the second shift toggle.

@khankuan
Copy link
Contributor Author

khankuan commented Nov 2, 2016

Ah interesting! Do you think we can use a method similar to

node.addEventListener('scroll', this.updateScrollTop);
, listen to keyup events.

@zalmoxisus
Copy link
Collaborator

@khankuan it would solve just a part of the problem. I think we should just return the previous value instead of null so it will not get dismissed while scrolling (initialScrollTop is dispatched).

@khankuan
Copy link
Contributor Author

khankuan commented Nov 3, 2016

Oh yes definitely meant that. But more importantly, would the keyup event method be the best way?

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Nov 3, 2016

@khankuan, no, listening to keyup events wouldn't be a solution, at least because actions can be removed due to reaching maxAge. Better and simpler is just to dismiss it (set to null) when handleToggleAction is called and to ignore consecutiveToggleStartId when the action with that id isn't present anymore.

@khankuan
Copy link
Contributor Author

@zalmoxisus sorry for the delay, updated accordingly here: 11e698c

@zalmoxisus
Copy link
Collaborator

@khankuan, no worries, thanks a lot for the changes. I see 2 issues here:

  1. Seems like you're not passing state to startConsecutiveToggle, but state.consecutiveToggleStartId.
  2. Handling the case when the action is not present anymore works great. Apart from that, shifting works only first time, then the first action will be always the same, and selecting a new start id will result in untoggling the interval.

@khankuan
Copy link
Contributor Author

Hmm, for 1, would there be any consequence of preserving via store state? For 2, I'm trying to understand it a little more. I was expecting the ux flow to be:

  • holds shift key
  • click on starting action
  • action gets "selected" to be the start
  • on the next user click on an action, if shift key is active, then trigger the consecutive toggle.

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Nov 30, 2016

Hmm, for 1, would there be any consequence of preserving via store state?

It just throws as you try to access state.consecutiveToggleStartId.consecutiveToggleStartId.

on the next user click on an action, if shift key is active, then trigger the consecutive toggle.

First time it will work as expected, then you'll not be able to select the first action anymore, as it is already selected (consecutiveToggleStartId is set and cannot be changed).

@zalmoxisus
Copy link
Collaborator

Hey @khankuan,

I'm merging this, will add the missing part in another PR. Thanks a lot for the contribution!

@zalmoxisus zalmoxisus changed the base branch from master to shift-toggle January 3, 2017 20:20
@zalmoxisus zalmoxisus merged commit fc216e0 into gaearon:shift-toggle Jan 3, 2017
zalmoxisus added a commit that referenced this pull request Jan 3, 2017
@zalmoxisus zalmoxisus mentioned this pull request Jan 3, 2017
@khankuan
Copy link
Contributor Author

khankuan commented Jan 4, 2017

@zalmoxisus thanks for maintaining this project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants