import { PlayOptions , ITimelineModel } from '../core/types' ; import { loopOn } from '../core/timeloop' ; import { S_PLAYING , _ } from '../utils/constants' ; import { update } from './update' ; import { PLAY } from '../actions' ; import { IReducer , IReducerContext } from '../core/types' ; export const play = ( model , options , ctx ) => { if ( options ) { model . repeat = options . repeat ; model . yoyo = ! ! options . alternate ; model . destroy = ! ! options . destroy ; } model . repeat = model . repeat || 1 ; model . yoyo = model . yoyo || false ; model . state = S_PLAYING ; const isForwards = model . rate >= 0 ; if ( isForwards && model . time === model . duration ) { model . time = 0 ; } else if ( ! isForwards && model . time === 0 ) { model . time = model . duration ; } loopOn ( model . id ) ; update ( model , _ , ctx ) ; ctx . trigger ( PLAY ) ; } ;