Populate SharedList

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Populate SharedList

Re: Populate SharedList

by drakinite » Tue Oct 11, 2022 7:45 pm

Hi there,

SharedLists are native Delphi objects, and can only contain native Delphi objects themselves (e.g. Track, Album, etc.) I believe that the unhelpful assertion failure is because the expected data type does not match. I'll see if it's possible to make the assert provide a more useful error message.

As for using .add() outside of modifyAsync: I was not aware, but yeah, it turns out you don't need to be inside of a write lock to use .add().
Here's an example of adding data to a SharedList. Realistically, you'll want the data type of all items within your list to be the same. But due to the way object-oriented inheritance works, it technically won't yell at you if you do this, and this is just to illustrate an example.

Code: Select all

myList = app.utils.createSharedList();
myTrack = app.utils.createEmptyTrack();
myAlbum = app.utils.createEmptyAlbum();
myList.beginUpdate(); // Optional; beginUpdate() and endUpdate() prevent the list from emitting any events while you're modifying it.
myList.add(myTrack);
myList.add(myAlbum);
myList.endUpdate();
If you want to use your own custom data, for ListViews (like a GridView), then you can use an ArrayDataSource. That class implements the methods from SharedLists that are used in LVs, such as locked(), modifyAsync(), and setAutoSort(), but in pure JS.

Since documentation on using ListViews in addons for your own purposes is sparse to the point of not existing, I spent tonight writing up a sample script demonstrating how you can use an ArrayDataSource to show your own custom data in a GridView. It includes comments explaining how it works. It'll be available inside the SampleScripts folder of the first 5.1 beta build, but here's a copy you can download and install/view now: https://1drv.ms/u/s!AqHzUrf30uprsodXCSh9dPFwpP3CMw

Populate SharedList

by heribertolugo » Mon Oct 10, 2022 11:54 am

attempting to populate SharedList i get a fatal assertion exception which crashes MM and does not mention what the assertion actually was. i tried to populate the SharedList in 2 different ways, both of which resulted in the same crash (Assertion Failure n:\Delphi\MediaMonkeyBuildTrunk\HTML5Monkey\ceflib.pas, line 22394).

Code: Select all

let data = app.utils.createSharedList();
let arr = [
        {path: 'bobo', isSomething: true},
        {path: 'momo', isSomething: false},
        {path: 'dodo', isSomething: true},
        {path: 'foo', isSomething: true},
        {path: 'bar', isSomething: false},
    ];
    
    for(let i =0; i < arr.length; i++) {
            data.add(arr[i]);
    }
and also

Code: Select all

let data = app.utils.createSharedList();
let arr = [
        {path: 'bobo', isSomething: true},
        {path: 'momo', isSomething: false},
        {path: 'dodo', isSomething: true},
        {path: 'foo', isSomething: true},
        {path: 'bar', isSomething: false},
    ];
    
    for(let i =0; i < arr.length; i++) {
        data.modifyAsync(() => {
            data.add(arr[i]);
        });
    }

i've found multiple examples in the code which just uses the add method (not modifyAsync).

how do i populate a shared list?

Top