55 ReactiveSetupAdapter
66} from "@cfcs/core" ;
77
8- import Flicking from "../Flicking" ;
8+ import Flicking , { FlickingOptions } from "../Flicking" ;
99
1010// Check if Flicking has reached the first panel
1111const getIsReachStart = ( flicking : Flicking ) => ! flicking . circular && flicking . index === 0 ;
@@ -137,7 +137,11 @@ export interface FlickingReactiveData {
137137 /**
138138 * Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
139139 */
140- flicking : Flicking | null ;
140+ flicking : Flicking | undefined ;
141+ /**
142+ * Flicking options used for initialization<ko>초기화에 사용되는 Flicking 옵션</ko>
143+ */
144+ options : FlickingOptions | undefined ;
141145}
142146
143147/**
@@ -158,11 +162,11 @@ FlickingReactiveState,
158162"moveTo" ,
159163FlickingReactiveData
160164> = ( { onInit, onDestroy, setMethods, getProps } ) => {
161- let flicking : Flicking | null = null ;
165+ let flicking : Flicking | undefined ;
162166
163167 // Move to a specific panel index
164168 const moveTo = ( i : number ) => {
165- if ( flicking === null ) {
169+ if ( flicking === undefined ) {
166170 return Promise . reject ( new Error ( "Flicking instance is not available" ) ) ;
167171 }
168172 if ( flicking ?. animating ) {
@@ -172,19 +176,23 @@ FlickingReactiveData
172176 } ;
173177 setMethods ( [ "moveTo" ] ) ;
174178
179+ const options = getProps ( ) . options ;
180+
181+ // options를 고려하지 않고 초기값을 설정해도 동작에는 아무런 문제가 없으나, 이 시점의 초기값과 컴포넌트 init 단계에서의 초기값이 다르면 화면 리렌더링이 발생할 수 있으므로
182+ // 이렇게 미리 옵션을 통해서 예측할 수 있는 부분들은 맞춰둔다.
175183 const reactiveObj : FlickingReactiveObject = reactive ( {
176- isReachStart : false , // 이 값을 전달 받은 옵션을 이용해서 설정. getProps()를 통해 전달된 옵션을 사용하여 설정할 수 있습니다.
177- isReachEnd : false , //
178- totalPanelCount : 0 , //
179- currentPanelIndex : 0 , //
180- progress : 0 , //
181- indexProgress : 0 , //
184+ isReachStart : ( options ?. defaultIndex === 0 && ! options . circular ) ,
185+ isReachEnd : false ,
186+ totalPanelCount : 0 ,
187+ currentPanelIndex : options ?. defaultIndex ?? 0 ,
188+ progress : 0 ,
189+ indexProgress : 0 ,
182190 moveTo
183191 } ) ;
184192
185193 // Update state when panel changes
186194 const onChanged = ( ) => {
187- if ( flicking === null ) return ;
195+ if ( flicking === undefined ) return ;
188196
189197 reactiveObj . isReachStart = getIsReachStart ( flicking ) ;
190198 reactiveObj . isReachEnd = getIsReachEnd ( flicking ) ;
@@ -193,23 +201,23 @@ FlickingReactiveData
193201
194202 // Update state when panel count changes
195203 const onPanelChange = ( ) => {
196- if ( flicking === null ) return ;
204+ if ( flicking === undefined ) return ;
197205
198206 onChanged ( ) ;
199207 reactiveObj . totalPanelCount = getTotalPanelCount ( flicking ) ;
200208 } ;
201209
202210 // Update progress when camera moves
203211 const onMove = ( ) => {
204- if ( flicking === null ) return ;
212+ if ( flicking === undefined ) return ;
205213
206214 reactiveObj . progress = getProgress ( flicking ) ;
207215 reactiveObj . indexProgress = getIndexProgress ( flicking ) ;
208216 } ;
209217
210218 onInit ( ( inst , data ) => {
211219 flicking = data . flicking ;
212- if ( flicking === null ) return ;
220+ if ( flicking === undefined ) return ;
213221
214222 reactiveObj . isReachStart = getIsReachStart ( flicking ) ;
215223 reactiveObj . isReachEnd = getIsReachEnd ( flicking ) ;
@@ -235,7 +243,8 @@ FlickingReactiveData
235243/**
236244 * Connect Flicking instance to reactive API
237245 * @ko Flicking 인스턴스를 반응형 API에 연결합니다
238- * @param flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
246+ * @param {Flicking } flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
247+ * @param {FlickingOptions } [options] - Flicking options<ko>Flicking 옵션</ko>
239248 * @returns {FlickingReactiveObject } Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
240249 * @example
241250 * ```js
@@ -261,8 +270,8 @@ FlickingReactiveData
261270 * reactiveObj.moveTo(2); // Move to third panel
262271 * ```
263272 */
264- const connectFlickingReactiveAPI = ( flicking : Flicking ) => {
265- const obj = adaptReactive ( flickingReactiveAPIAdapter , ( ) => ( { flicking } ) ) ;
273+ const connectFlickingReactiveAPI = ( flicking : Flicking , options ?: FlickingOptions ) => {
274+ const obj = adaptReactive ( flickingReactiveAPIAdapter , ( ) => ( { flicking, options } ) ) ;
266275 obj . mounted ( ) ;
267276 const instance = obj . instance ( ) ;
268277 obj . init ( ) ;
0 commit comments