@@ -7,6 +7,7 @@ import { tracked } from '@glimmer/tracking';
77import type { LiveQuery , Store } from 'ember-orbit' ;
88
99import type { RecordOperationTerm } from '@orbit/records' ;
10+ import { TrackedArray } from 'tracked-built-ins' ;
1011
1112import type ApplicationController from 'swach/controllers/application' ;
1213import type ColorModel from 'swach/data-models/color' ;
@@ -166,7 +167,7 @@ export default class PalettesController extends Controller {
166167 ...attributes ,
167168 createdAt : new Date ( ) ,
168169 } ;
169- const colorsList = targetList . map ( ( c ) => c . $identity ) ;
170+ const colorsList = new TrackedArray ( targetList . map ( ( c ) => c . $identity ) ) ;
170171
171172 const existingColor = targetList . find ( ( c ) => c . hex === sourceColor . hex ) ;
172173
@@ -178,7 +179,7 @@ export default class PalettesController extends Controller {
178179 }
179180 }
180181
181- colorsList . insertAt ( targetIndex , {
182+ colorsList . splice ( targetIndex , 0 , {
182183 type : 'color' ,
183184 id : colorCopy . id ,
184185 } ) ;
@@ -208,12 +209,14 @@ export default class PalettesController extends Controller {
208209 sourcePalette : PaletteModel ,
209210 targetIndex : number ,
210211 ) : Promise < void > {
211- const sourceColorList = sourceList . map ( ( c ) => c . $identity ) ;
212- const colorToMove = sourceColorList . findBy ( 'id' , sourceColor . id ) ;
212+ const sourceColorList = new TrackedArray (
213+ sourceList . map ( ( c ) => c . $identity ) ,
214+ ) ;
215+ const colorToMove = sourceColorList . find ( ( c ) => c . id === sourceColor . id ) ;
213216
214217 if ( colorToMove ) {
215218 sourceColorList . removeObject ( colorToMove ) ;
216- sourceColorList . insertAt ( targetIndex , colorToMove ) ;
219+ sourceColorList . splice ( targetIndex , 0 , colorToMove ) ;
217220
218221 await this . store . update ( ( t ) =>
219222 t . replaceAttribute ( sourcePalette , 'colorOrder' , sourceColorList ) ,
@@ -233,7 +236,7 @@ export default class PalettesController extends Controller {
233236 targetPalette : PaletteModel ,
234237 ) : Promise < void > {
235238 const sourceColorOrder = sourceList . map ( ( c ) => c . $identity ) ;
236- const colorToRemove = sourceColorOrder . findBy ( 'id' , sourceColor . id ) ;
239+ const colorToRemove = sourceColorOrder . find ( ( c ) => c . id === sourceColor . id ) ;
237240
238241 if ( colorToRemove ) {
239242 sourceColorOrder . removeObject ( colorToRemove ) ;
@@ -246,13 +249,16 @@ export default class PalettesController extends Controller {
246249
247250 if ( ! targetPalette . isColorHistory ) {
248251 let insertIndex = targetIndex ;
249- const targetColorOrder = targetList . map ( ( c ) => c . $identity ) ;
250- const existingColor = targetList . findBy ( 'hex' , sourceColor . hex ) ;
252+ const targetColorOrder = new TrackedArray (
253+ targetList . map ( ( c ) => c . $identity ) ,
254+ ) ;
255+ const existingColor = targetList . find (
256+ ( c ) => c . hex === sourceColor . hex ,
257+ ) ;
251258
252259 if ( existingColor ) {
253- const colorToRemove = targetColorOrder . findBy (
254- 'id' ,
255- existingColor . id ,
260+ const colorToRemove = targetColorOrder . find (
261+ ( c ) => c . id === existingColor . id ,
256262 ) ;
257263
258264 if ( colorToRemove ) {
@@ -270,8 +276,7 @@ export default class PalettesController extends Controller {
270276
271277 t . removeFromRelatedRecords ( targetPalette , 'colors' , existingColor ) ;
272278 }
273-
274- targetColorOrder . insertAt ( insertIndex , sourceColor . $identity ) ;
279+ targetColorOrder . splice ( insertIndex , 0 , sourceColor . $identity ) ;
275280
276281 operations . push (
277282 t . addToRelatedRecords ( targetPalette , 'colors' , sourceColor ) ,
0 commit comments