@@ -143,10 +143,10 @@ Here's the reference implementation of the `dragEndAction` action:
143143 dragEndAction ({sourceList, sourceIndex, targetList, targetIndex/* , sourceArgs, targetArgs */ }) {
144144 if (sourceList === targetList && sourceIndex === targetIndex) return
145145
146- const item = sourceList . objectAt ( sourceIndex)
146+ const item = sourceList[ sourceIndex]
147147
148- sourceList .removeAt (sourceIndex)
149- targetList .insertAt (targetIndex, item)
148+ sourceList .splice (sourceIndex, 1 )
149+ targetList .splice (targetIndex, 0 , item)
150150 }
151151```
152152
@@ -236,10 +236,10 @@ Or do it by hand:
236236``` js
237237@action
238238determineForeignPosition ({draggedItem, items}) {
239- return Ember . A ( items .slice ()) // make sure not to mutate the list; `Ember.A()` is typically redundant
240- . addObject (draggedItem)
241- . sortBy ( ' name' )
242- .indexOf (draggedItem)
239+ const itemsCopy = items .slice (); // make sure not to mutate the list
240+ itemsCopy . push (draggedItem);
241+ itemsCopy . sort (( a , b ) => a . name . localeCompare ( b . name ));
242+ return itemsCopy .indexOf (draggedItem);
243243}
244244```
245245
@@ -294,9 +294,9 @@ Now you can access the parent of both source and target lists in the `dragEndAct
294294dragEndAction ({ sourceList, sourceIndex, sourceArgs, targetList, targetIndex, targetArgs }) {
295295 if (sourceModel === targetModel && sourceIndex === targetIndex) return ;
296296
297- const item = sourceList . objectAt ( sourceIndex) ;
298- sourceList .removeAt (sourceIndex);
299- targetList .insertAt (targetIndex, item);
297+ const item = sourceList[ sourceIndex] ;
298+ sourceList .splice (sourceIndex, 1 );
299+ targetList .splice (targetIndex, 0 , item);
300300
301301 // Access the parent via `sourceArgs` and `targetArgs`
302302 sourceArgs .parent .save ();
@@ -600,12 +600,12 @@ export default create({
600600});
601601```
602602
603- In a test, list items are available as ` sortableList.items ` . Item content is available as ` sortableList.items.objectAt( index) ` .
603+ In a test, list items are available as ` sortableList.items ` . Item content is available as ` sortableList.items[ index] ` .
604604
605605For example, to assert the title of the first item in a list, using the page object from the last example, you can do this:
606606
607607``` js
608- assert .strictEqual (sortableList .items . objectAt ( 0 ) .item .content .title , " Foo" );
608+ assert .strictEqual (sortableList .items [ 0 ] .item .content .title , " Foo" );
609609```
610610
611611#### Providing the drag handle selector
@@ -660,7 +660,7 @@ test('sorting a list', async function (assert) {
660660
661661 expectedTitles .forEach ((expectedTitle , k ) => {
662662 m = ` List #0 item #${ k} content title`
663- expect (list .items . objectAt (k) .item .title , m).equal (expectedTitle)
663+ expect (list .items [k] .item .title , m).equal (expectedTitle)
664664 })
665665}))
666666```
0 commit comments