score:1

just show me an example

this doesn't use immutable.js, but the current property is just a number, which is immutable in js, so in some regards it's the same idea:

http://jsbin.com/ligejacolo/edit?js,output

imo the best option is reactcsstransitiongroup

+1 for the unnecessarily snarky reference to reactcsstransitiongroup in the comments, if you can use that.

after that, let the browser manage state via css transitions

i would store the pages and currentpage as props, regardless of whether the values are immutable.js instances (props are a stateful part of your ui, just like state, don't let the name fool you!). when they're stored as props, it provides a useful api to the users of your component.

if you're using css transitions then at any given moment you should be able to render the markup and classes based on this information.

for example, given the (over-simplified markup):

<div class=container>
  <!-- set the class to something like "inner pane2" to go to the second pane -->
  <div class=inner>
    <span class=pane>...</span>
    <span class=pane>...</span>
    <span class=pane>...</span>
  </div>
</div>

and some css like:

.container {
  position: relative;
}

.inner {
  position: absolute;
  left: 0;
  transition: left 0.3s ease-in-out;
}

.pane {
  width: 100px;
}

.inner.pane2 {
  left: -100px;
}

.inner.pane3 {
  left: -200px;
}

the browser takes care of mid-transition changes to the properties.

often times you'll need to know when the animation is done, which you can accomplish with a transitionend listener and isanimating flag (which i would store in the state, not the props). set isanimating when currentpage changes and clear it on transitionend.

you'll also often need to know which direction you're transitioning, which you can accomplish with a previouspage prop.

finally, if you're just using javascript

keep a reference to the current transition in the state (possibly the jquery selection used to start the animation, if that's what you're using). when the transition is done, remove the reference. if the currentpage changes mid-transition, call .stop() on the selection (or whatever api you're using).


Related Query

More Query from same tag