import Transitions, { Units } from '../../src/index' import { ActionsType, Cmd } from 'hydux' import { React } from 'hydux/lib/enhancers/picodom-render' export const state = { slides: ['red', 'yellow', 'blue'], currents: { prev: 0, next: 1, }, index: 0, direction: 'left' as 'left' | 'right', right: { prev: Transitions.init([{ translateX: Units.percent(100), duration: Units.ms(600), }]), next: Transitions.init([{ translateX: Units.percent(0), duration: Units.ms(600), }], { initFrame: { translateX: Units.percent(-100), } }) }, left: { prev: Transitions.init([{ translateX: Units.percent(-100), duration: Units.ms(600), }]), next: Transitions.init([{ translateX: Units.percent(0), duration: Units.ms(600), }], { initFrame: { translateX: Units.percent(100), } }) }, } export const actions = { left: { prev: Transitions.actions, next: Transitions.actions, }, right: { prev: Transitions.actions, next: Transitions.actions, }, goLeft: () => (state: State, actions: Actions) => { let next = state.index + 1 if (next === state.slides.length) { next = 0 } return [{ ...state, index: next, currents: { prev: state.index, next }, direction: 'left', }, Cmd.ofSub(actions => { actions.left.prev.start() actions.left.next.start() })] }, goRight: () => (state: State, actions: Actions) => { let next = state.index - 1 if (next === -1) { next = state.slides.length - 1 } return [{ ...state, index: next, currents: { prev: state.index, next }, direction: 'right', }, Cmd.ofSub(actions => { actions.right.prev.start() actions.right.next.start() })] }, } export const init = () => state export const view = (state: State, actions: Actions) => { return (

console.log('clicked', state.slides[state.currents.prev])} className={state[state.direction].prev.className} />
console.log('clicked', state.slides[state.currents.next])} className={state[state.direction].next.className} />

) } export type State = typeof state export type Actions = typeof actions